1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_SETUP_H_ 6 #define CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_SETUP_H_ 7 #pragma once 8 9 #include "include/base/cef_logging.h" 10 #include "include/base/cef_macros.h" 11 12 namespace client { 13 namespace performance_test { 14 15 // Default number of iterations. 16 extern const int kDefaultIterations; 17 18 // Test name. 19 #define PERF_TEST_NAME(name) PerfTest##name 20 21 // Entry in test array. 22 #define PERF_TEST_ENTRY_EX(name, iterations) \ 23 { #name, PERF_TEST_NAME(name), iterations } 24 #define PERF_TEST_ENTRY(name) PERF_TEST_ENTRY_EX(name, kDefaultIterations) 25 26 // Test function declaration. 27 #define PERF_TEST_RESULT int64 28 #define PERF_TEST_PARAM_ITERATIONS iterations 29 #define PERF_TEST_PARAMS int PERF_TEST_PARAM_ITERATIONS 30 #define PERF_TEST_FUNC(name) \ 31 PERF_TEST_RESULT PERF_TEST_NAME(name)(PERF_TEST_PARAMS) 32 33 // Typedef for test pointers. 34 typedef PERF_TEST_RESULT(PerfTest(PERF_TEST_PARAMS)); 35 36 class CefTimer { 37 public: CefTimer()38 CefTimer() : running_(false) {} 39 IsRunning()40 bool IsRunning() { return running_; } 41 Start()42 void Start() { 43 DCHECK(!running_); 44 running_ = true; 45 start_.Now(); 46 } 47 Stop()48 void Stop() { 49 stop_.Now(); 50 DCHECK(running_); 51 running_ = false; 52 } 53 Delta()54 int64 Delta() { 55 DCHECK(!running_); 56 return start_.Delta(stop_); 57 } 58 59 private: 60 bool running_; 61 CefTime start_; 62 CefTime stop_; 63 64 DISALLOW_COPY_AND_ASSIGN(CefTimer); 65 }; 66 67 // Peform test iterations using a user-provided timing result variable. 68 #define PERF_ITERATIONS_START_EX() \ 69 { \ 70 CefTimer _timer; \ 71 _timer.Start(); \ 72 for (int _i = 0; _i < PERF_TEST_PARAM_ITERATIONS; ++_i) { 73 #define PERF_ITERATIONS_END_EX(result) \ 74 } \ 75 _timer.Stop(); \ 76 result = _timer.Delta(); \ 77 } 78 79 // Perform test iterations and return the timing result. 80 #define PERF_ITERATIONS_START() \ 81 int64 _result = 0; \ 82 PERF_ITERATIONS_START_EX() 83 84 #define PERF_ITERATIONS_END() \ 85 PERF_ITERATIONS_END_EX(_result) \ 86 return _result; 87 88 // Perf test entry structure. 89 struct PerfTestEntry { 90 const char* name; 91 PerfTest* test; 92 int iterations; 93 }; 94 95 // Array of perf tests. 96 extern const PerfTestEntry kPerfTests[]; 97 extern const int kPerfTestsCount; 98 99 } // namespace performance_test 100 } // namespace client 101 102 #endif // CEF_TESTS_CEFCLIENT_RENDERER_PERFORMANCE_TEST_H_ 103