2012-10-26 22:42:41 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_SETUP_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_SETUP_H_
|
2012-10-26 22:42:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
2014-07-11 22:10:05 +02:00
|
|
|
#include "include/base/cef_logging.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/base/cef_macros.h"
|
2012-10-26 22:42:41 +02:00
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
namespace client::performance_test {
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
// Default number of iterations.
|
2013-08-14 23:45:22 +02:00
|
|
|
extern const int kDefaultIterations;
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
// Test name.
|
|
|
|
#define PERF_TEST_NAME(name) PerfTest##name
|
|
|
|
|
|
|
|
// Entry in test array.
|
|
|
|
#define PERF_TEST_ENTRY_EX(name, iterations) \
|
2017-05-17 11:29:28 +02:00
|
|
|
{ #name, PERF_TEST_NAME(name), iterations }
|
2012-10-26 22:42:41 +02:00
|
|
|
#define PERF_TEST_ENTRY(name) PERF_TEST_ENTRY_EX(name, kDefaultIterations)
|
|
|
|
|
|
|
|
// Test function declaration.
|
2023-06-01 16:06:15 +02:00
|
|
|
#define PERF_TEST_RESULT int64_t
|
2012-10-26 22:42:41 +02:00
|
|
|
#define PERF_TEST_PARAM_ITERATIONS iterations
|
2013-08-14 23:45:22 +02:00
|
|
|
#define PERF_TEST_PARAMS int PERF_TEST_PARAM_ITERATIONS
|
2012-10-26 22:42:41 +02:00
|
|
|
#define PERF_TEST_FUNC(name) \
|
2017-05-17 11:29:28 +02:00
|
|
|
PERF_TEST_RESULT PERF_TEST_NAME(name)(PERF_TEST_PARAMS)
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
// Typedef for test pointers.
|
|
|
|
typedef PERF_TEST_RESULT(PerfTest(PERF_TEST_PARAMS));
|
|
|
|
|
|
|
|
class CefTimer {
|
|
|
|
public:
|
2024-01-20 03:22:56 +01:00
|
|
|
CefTimer() = default;
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
bool IsRunning() { return running_; }
|
|
|
|
|
|
|
|
void Start() {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(!running_);
|
2012-10-26 22:42:41 +02:00
|
|
|
running_ = true;
|
|
|
|
start_.Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stop() {
|
|
|
|
stop_.Now();
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(running_);
|
2012-10-26 22:42:41 +02:00
|
|
|
running_ = false;
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t Delta() {
|
2014-07-11 22:10:05 +02:00
|
|
|
DCHECK(!running_);
|
2012-10-26 22:42:41 +02:00
|
|
|
return start_.Delta(stop_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2024-01-20 03:22:56 +01:00
|
|
|
bool running_ = false;
|
2012-10-26 22:42:41 +02:00
|
|
|
CefTime start_;
|
|
|
|
CefTime stop_;
|
2014-07-11 22:10:05 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefTimer);
|
2012-10-26 22:42:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Peform test iterations using a user-provided timing result variable.
|
|
|
|
#define PERF_ITERATIONS_START_EX() \
|
2017-05-17 11:29:28 +02:00
|
|
|
{ \
|
|
|
|
CefTimer _timer; \
|
|
|
|
_timer.Start(); \
|
|
|
|
for (int _i = 0; _i < PERF_TEST_PARAM_ITERATIONS; ++_i) {
|
2012-10-26 22:42:41 +02:00
|
|
|
#define PERF_ITERATIONS_END_EX(result) \
|
2017-05-17 11:29:28 +02:00
|
|
|
} \
|
|
|
|
_timer.Stop(); \
|
|
|
|
result = _timer.Delta(); \
|
|
|
|
}
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
// Perform test iterations and return the timing result.
|
|
|
|
#define PERF_ITERATIONS_START() \
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t _result = 0; \
|
2017-05-17 11:29:28 +02:00
|
|
|
PERF_ITERATIONS_START_EX()
|
2012-10-26 22:42:41 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define PERF_ITERATIONS_END() \
|
|
|
|
PERF_ITERATIONS_END_EX(_result) \
|
|
|
|
return _result;
|
2012-10-26 22:42:41 +02:00
|
|
|
|
|
|
|
// Perf test entry structure.
|
|
|
|
struct PerfTestEntry {
|
|
|
|
const char* name;
|
|
|
|
PerfTest* test;
|
2013-08-14 23:45:22 +02:00
|
|
|
int iterations;
|
2012-10-26 22:42:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Array of perf tests.
|
|
|
|
extern const PerfTestEntry kPerfTests[];
|
2013-08-14 23:45:22 +02:00
|
|
|
extern const int kPerfTestsCount;
|
2012-10-26 22:42:41 +02:00
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
} // namespace client::performance_test
|
2012-10-26 22:42:41 +02:00
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_H_
|