From ce76bfc1e12236d521a16e5c9e768bbfe1ec928c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 26 Oct 2012 20:39:24 +0000 Subject: [PATCH] Add performance tests for CEF V8 methods (issue #484). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@879 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/cef_paths2.gypi | 10 +- cef1/include/internal/cef_time.h | 12 + cef1/include/internal/cef_types_wrappers.h | 12 + cef1/libcef/cef_time.cc | 24 ++ cef1/tests/cefclient/cefclient.rc | 4 +- cef1/tests/cefclient/cefclient_gtk.cpp | 11 + cef1/tests/cefclient/cefclient_mac.mm | 19 +- cef1/tests/cefclient/cefclient_win.cpp | 9 +- cef1/tests/cefclient/client_handler.cpp | 9 +- cef1/tests/cefclient/client_handler_gtk.cpp | 5 + cef1/tests/cefclient/client_handler_mac.mm | 5 + cef1/tests/cefclient/client_handler_win.cpp | 5 + cef1/tests/cefclient/extension_test.cpp | 19 +- cef1/tests/cefclient/extension_test.h | 1 - cef1/tests/cefclient/performance_test.cpp | 98 ++++++ cef1/tests/cefclient/performance_test.h | 28 ++ cef1/tests/cefclient/performance_test_setup.h | 99 ++++++ .../cefclient/performance_test_tests.cpp | 328 ++++++++++++++++++ cef1/tests/cefclient/res/extensionperf.html | 131 ------- cef1/tests/cefclient/res/performance.html | 293 ++++++++++++++++ cef1/tests/cefclient/resource.h | 4 +- 21 files changed, 955 insertions(+), 171 deletions(-) create mode 100644 cef1/tests/cefclient/performance_test.cpp create mode 100644 cef1/tests/cefclient/performance_test.h create mode 100644 cef1/tests/cefclient/performance_test_setup.h create mode 100644 cef1/tests/cefclient/performance_test_tests.cpp delete mode 100644 cef1/tests/cefclient/res/extensionperf.html create mode 100644 cef1/tests/cefclient/res/performance.html diff --git a/cef1/cef_paths2.gypi b/cef1/cef_paths2.gypi index fcd5efc05..c71f1472d 100644 --- a/cef1/cef_paths2.gypi +++ b/cef1/cef_paths2.gypi @@ -93,10 +93,14 @@ 'tests/cefclient/download_handler.h', 'tests/cefclient/extension_test.cpp', 'tests/cefclient/extension_test.h', + 'tests/cefclient/performance_test.cpp', + 'tests/cefclient/performance_test.h', + 'tests/cefclient/performance_test_setup.h', + 'tests/cefclient/performance_test_tests.cpp', 'tests/cefclient/res/domaccess.html', - 'tests/cefclient/res/extensionperf.html', 'tests/cefclient/res/localstorage.html', 'tests/cefclient/res/logo.png', + 'tests/cefclient/res/performance.html', 'tests/cefclient/res/xmlhttprequest.html', 'tests/cefclient/resource_util.h', 'tests/cefclient/scheme_test.cpp', @@ -149,10 +153,10 @@ 'tests/cefclient/mac/English.lproj/MainMenu.xib', 'tests/cefclient/mac/Info.plist', 'tests/cefclient/res/domaccess.html', - 'tests/cefclient/res/extensionperf.html', 'tests/cefclient/res/localstorage.html', 'tests/cefclient/res/logo.png', 'tests/cefclient/res/logoball.png', + 'tests/cefclient/res/performance.html', 'tests/cefclient/res/osrtest.html', 'tests/cefclient/res/transparency.html', 'tests/cefclient/res/xmlhttprequest.html', @@ -164,9 +168,9 @@ ], 'cefclient_bundle_resources_linux': [ 'tests/cefclient/res/domaccess.html', - 'tests/cefclient/res/extensionperf.html', 'tests/cefclient/res/localstorage.html', 'tests/cefclient/res/logo.png', + 'tests/cefclient/res/performance.html', 'tests/cefclient/res/xmlhttprequest.html', ], }, diff --git a/cef1/include/internal/cef_time.h b/cef1/include/internal/cef_time.h index ccaf19320..64e601fe0 100644 --- a/cef1/include/internal/cef_time.h +++ b/cef1/include/internal/cef_time.h @@ -69,6 +69,18 @@ CEF_EXPORT int cef_time_from_timet(time_t time, cef_time_t* cef_time); CEF_EXPORT int cef_time_to_doublet(const cef_time_t* cef_time, double* time); CEF_EXPORT int cef_time_from_doublet(double time, cef_time_t* cef_time); +/// +// Retrieve the current system time. +// +CEF_EXPORT int cef_time_now(cef_time_t* cef_time); + +/// +// Retrieve the delta in milliseconds between two time values. +// +CEF_EXPORT int cef_time_delta(const cef_time_t* cef_time1, + const cef_time_t* cef_time2, + long long* delta); + #ifdef __cplusplus } #endif diff --git a/cef1/include/internal/cef_types_wrappers.h b/cef1/include/internal/cef_types_wrappers.h index 909f5e636..11252b2d5 100644 --- a/cef1/include/internal/cef_types_wrappers.h +++ b/cef1/include/internal/cef_types_wrappers.h @@ -499,6 +499,18 @@ class CefTime : public CefStructBase { cef_time_to_doublet(this, &time); return time; } + + // Set this object to now. + void Now() { + cef_time_now(this); + } + + // Return the delta between this object and |other| in milliseconds. + int64 Delta(const CefTime& other) { + int64 delta = 0; + cef_time_delta(this, &other, &delta); + return delta; + } }; diff --git a/cef1/libcef/cef_time.cc b/cef1/libcef/cef_time.cc index cc28c8dcd..47a70a846 100644 --- a/cef1/libcef/cef_time.cc +++ b/cef1/libcef/cef_time.cc @@ -67,3 +67,27 @@ CEF_EXPORT int cef_time_from_doublet(double time, cef_time_t* cef_time) { cef_time_from_basetime(base_time, *cef_time); return 1; } + +CEF_EXPORT int cef_time_now(cef_time_t* cef_time) { + if (!cef_time) + return 0; + + base::Time base_time = base::Time::Now(); + cef_time_from_basetime(base_time, *cef_time); + return 1; +} + +CEF_EXPORT int cef_time_delta(const cef_time_t* cef_time1, + const cef_time_t* cef_time2, + long long* delta) { + if (!cef_time1 || !cef_time2 || !delta) + return 0; + + base::Time base_time1, base_time2; + cef_time_to_basetime(*cef_time1, base_time1); + cef_time_to_basetime(*cef_time2, base_time2); + + base::TimeDelta time_delta = base_time2 - base_time1; + *delta = time_delta.InMilliseconds(); + return 1; +} diff --git a/cef1/tests/cefclient/cefclient.rc b/cef1/tests/cefclient/cefclient.rc index 94e39b995..45b82e33e 100644 --- a/cef1/tests/cefclient/cefclient.rc +++ b/cef1/tests/cefclient/cefclient.rc @@ -37,7 +37,7 @@ IDS_XMLHTTPREQUEST BINARY "res\\xmlhttprequest.html" IDS_DOMACCESS BINARY "res\\domaccess.html" IDS_MODALMAIN BINARY "res\\modalmain.html" IDS_MODALDIALOG BINARY "res\\modaldialog.html" -IDS_EXTENSIONPERF BINARY "res\\extensionperf.html" +IDS_PERFORMANCE BINARY "res\\performance.html" IDS_TRANSPARENCY BINARY "res\\transparency.html" ///////////////////////////////////////////////////////////////////////////// @@ -75,9 +75,9 @@ BEGIN MENUITEM "Get Text", ID_TESTS_GETTEXT MENUITEM "JavaScript Binding Handler", ID_TESTS_JAVASCRIPT_BINDING MENUITEM "JavaScript Extension Handler",ID_TESTS_JAVASCRIPT_EXTENSION - MENUITEM "JavaScript Extension Performance",ID_TESTS_JAVASCRIPT_PERFORMANCE MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE MENUITEM "JavaScript Invoke", ID_TESTS_JAVASCRIPT_INVOKE + MENUITEM "Performance Tests", ID_TESTS_PERFORMANCE MENUITEM "Plugin", ID_TESTS_PLUGIN MENUITEM "Plugin Info", ID_TESTS_PLUGIN_INFO MENUITEM "Popup Window", ID_TESTS_POPUP diff --git a/cef1/tests/cefclient/cefclient_gtk.cpp b/cef1/tests/cefclient/cefclient_gtk.cpp index f7655db19..15f40c0fc 100644 --- a/cef1/tests/cefclient/cefclient_gtk.cpp +++ b/cef1/tests/cefclient/cefclient_gtk.cpp @@ -14,6 +14,7 @@ #include "cefclient/binding_test.h" #include "cefclient/client_handler.h" #include "cefclient/extension_test.h" +#include "cefclient/performance_test.h" #include "cefclient/scheme_test.h" #include "cefclient/string_util.h" @@ -70,6 +71,14 @@ gboolean JSExecuteActivated(GtkWidget* widget) { return FALSE; // Don't stop this message. } +// Callback for Debug > Performance Tests... menu item. +gboolean PerformanceActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserHwnd()) + performance_test::RunTest(g_handler->GetBrowser()); + + return FALSE; // Don't stop this message. +} + // Callback for Debug > Request... menu item. gboolean RequestActivated(GtkWidget* widget) { if (g_handler.get() && g_handler->GetBrowserHwnd()) @@ -280,6 +289,8 @@ GtkWidget* CreateMenuBar() { G_CALLBACK(JSExtensionActivated)); AddMenuEntry(debug_menu, "JS Execute", G_CALLBACK(JSExecuteActivated)); + AddMenuEntry(debug_menu, "Performance Tests", + G_CALLBACK(PerformanceActivated)); AddMenuEntry(debug_menu, "Request", G_CALLBACK(RequestActivated)); AddMenuEntry(debug_menu, "Local Storage", diff --git a/cef1/tests/cefclient/cefclient_mac.mm b/cef1/tests/cefclient/cefclient_mac.mm index 8682810a2..6ae762546 100644 --- a/cef1/tests/cefclient/cefclient_mac.mm +++ b/cef1/tests/cefclient/cefclient_mac.mm @@ -15,6 +15,7 @@ #include "cefclient/client_handler.h" #include "cefclient/extension_test.h" #include "cefclient/osrtest_mac.h" +#include "cefclient/performance_test.h" #include "cefclient/resource_util.h" #include "cefclient/scheme_test.h" #include "cefclient/string_util.h" @@ -192,9 +193,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { - (IBAction)testGetText:(id)sender; - (IBAction)testJSBinding:(id)sender; - (IBAction)testJSExtension:(id)sender; -- (IBAction)testJSExtensionPerf:(id)sender; - (IBAction)testJSExecute:(id)sender; - (IBAction)testJSInvoke:(id)sender; +- (IBAction)testPerformance:(id)sender; - (IBAction)testRequest:(id)sender; - (IBAction)testLocalStorage:(id)sender; - (IBAction)testXMLHttpRequest:(id)sender; @@ -245,15 +246,15 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { [testMenu addItemWithTitle:@"JavaScript Extension Handler" action:@selector(testJSExtension:) keyEquivalent:@""]; - [testMenu addItemWithTitle:@"JavaScript Extension Performance" - action:@selector(testJSExtensionPerf:) - keyEquivalent:@""]; [testMenu addItemWithTitle:@"JavaScript Execute" action:@selector(testJSExecute:) keyEquivalent:@""]; [testMenu addItemWithTitle:@"JavaScript Invoke" action:@selector(testJSInvoke:) keyEquivalent:@""]; + [testMenu addItemWithTitle:@"Performance Tests" + action:@selector(testPerformance:) + keyEquivalent:@""]; [testMenu addItemWithTitle:@"Popup Window" action:@selector(testPopupWindow:) keyEquivalent:@""]; @@ -425,11 +426,6 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { RunExtensionTest(g_handler->GetBrowser()); } -- (IBAction)testJSExtensionPerf:(id)sender { - if (g_handler.get() && g_handler->GetBrowserHwnd()) - RunExtensionPerfTest(g_handler->GetBrowser()); -} - - (IBAction)testJSExecute:(id)sender { if (g_handler.get() && g_handler->GetBrowserHwnd()) RunJavaScriptExecuteTest(g_handler->GetBrowser()); @@ -440,6 +436,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { RunJavaScriptInvokeTest(g_handler->GetBrowser()); } +- (IBAction)testPerformance:(id)sender { + if (g_handler.get() && g_handler->GetBrowserHwnd()) + performance_test::RunTest(g_handler->GetBrowser()); +} + - (IBAction)testRequest:(id)sender { if (g_handler.get() && g_handler->GetBrowserHwnd()) RunRequestTest(g_handler->GetBrowser()); diff --git a/cef1/tests/cefclient/cefclient_win.cpp b/cef1/tests/cefclient/cefclient_win.cpp index 0d0220530..2b985bafa 100644 --- a/cef1/tests/cefclient/cefclient_win.cpp +++ b/cef1/tests/cefclient/cefclient_win.cpp @@ -17,6 +17,7 @@ #include "cefclient/client_handler.h" #include "cefclient/extension_test.h" #include "cefclient/osrplugin_test.h" +#include "cefclient/performance_test.h" #include "cefclient/plugin_test.h" #include "cefclient/resource.h" #include "cefclient/scheme_test.h" @@ -448,10 +449,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, if (browser.get()) RunExtensionTest(browser); return 0; - case ID_TESTS_JAVASCRIPT_PERFORMANCE: // Test the V8 performance - if (browser.get()) - RunExtensionPerfTest(browser); - return 0; case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript if (browser.get()) RunJavaScriptExecuteTest(browser); @@ -460,6 +457,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, if (browser.get()) RunJavaScriptInvokeTest(browser); return 0; + case ID_TESTS_PERFORMANCE: // Run performance tests + if (browser.get()) + performance_test::RunTest(browser); + return 0; case ID_TESTS_PLUGIN: // Test the custom plugin if (browser.get()) RunPluginTest(browser); diff --git a/cef1/tests/cefclient/client_handler.cpp b/cef1/tests/cefclient/client_handler.cpp index 9a72fd692..326ac3972 100644 --- a/cef1/tests/cefclient/client_handler.cpp +++ b/cef1/tests/cefclient/client_handler.cpp @@ -13,6 +13,7 @@ #include "cefclient/cefclient.h" #include "cefclient/cefclient_switches.h" #include "cefclient/download_handler.h" +#include "cefclient/performance_test.h" #include "cefclient/string_util.h" ClientHandler::ClientHandler() @@ -262,8 +263,14 @@ void ClientHandler::OnContextCreated(CefRefPtr browser, CefRefPtr context) { REQUIRE_UI_THREAD(); + CefRefPtr object = context->GetGlobal(); + // Add the V8 bindings. - InitBindingTest(browser, frame, context->GetGlobal()); + InitBindingTest(browser, frame, object); + + std::string url = frame->GetURL(); + if (url == performance_test::kTestUrl) + performance_test::InitTest(browser, frame, object); } bool ClientHandler::OnDragStart(CefRefPtr browser, diff --git a/cef1/tests/cefclient/client_handler_gtk.cpp b/cef1/tests/cefclient/client_handler_gtk.cpp index 68be0c0b1..7df19a66a 100644 --- a/cef1/tests/cefclient/client_handler_gtk.cpp +++ b/cef1/tests/cefclient/client_handler_gtk.cpp @@ -7,6 +7,7 @@ #include "cefclient/client_handler.h" #include "include/cef_browser.h" #include "include/cef_frame.h" +#include "cefclient/performance_test.h" #include "cefclient/resource_util.h" #include "cefclient/string_util.h" @@ -61,6 +62,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr browser, resourceStream = GetBinaryResourceReader("domaccess.html"); response->SetMimeType("text/html"); response->SetStatus(200); + } else if (url == performance_test::kTestUrl) { + resourceStream = GetBinaryResourceReader("performance.html"); + response->SetMimeType("text/html"); + response->SetStatus(200); } return false; diff --git a/cef1/tests/cefclient/client_handler_mac.mm b/cef1/tests/cefclient/client_handler_mac.mm index 3eb5a6615..669f605cc 100644 --- a/cef1/tests/cefclient/client_handler_mac.mm +++ b/cef1/tests/cefclient/client_handler_mac.mm @@ -8,6 +8,7 @@ #include "include/cef_browser.h" #include "include/cef_frame.h" #include "cefclient/cefclient.h" +#include "cefclient/performance_test.h" #include "cefclient/resource_util.h" #include "cefclient/string_util.h" @@ -75,6 +76,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr browser, resourceStream = GetBinaryResourceReader("domaccess.html"); response->SetMimeType("text/html"); response->SetStatus(200); + } else if (url == performance_test::kTestUrl) { + resourceStream = GetBinaryResourceReader("performance.html"); + response->SetMimeType("text/html"); + response->SetStatus(200); } return false; diff --git a/cef1/tests/cefclient/client_handler_win.cpp b/cef1/tests/cefclient/client_handler_win.cpp index 187a2fa0a..ea5f68a81 100644 --- a/cef1/tests/cefclient/client_handler_win.cpp +++ b/cef1/tests/cefclient/client_handler_win.cpp @@ -6,6 +6,7 @@ #include #include "include/cef_browser.h" #include "include/cef_frame.h" +#include "cefclient/performance_test.h" #include "cefclient/resource.h" #include "cefclient/resource_util.h" #include "cefclient/string_util.h" @@ -115,6 +116,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr browser, html.size()); response->SetMimeType("text/html"); response->SetStatus(200); + } else if (url == performance_test::kTestUrl) { + resourceStream = GetBinaryResourceReader(IDS_PERFORMANCE); + response->SetMimeType("text/html"); + response->SetStatus(200); } return false; diff --git a/cef1/tests/cefclient/extension_test.cpp b/cef1/tests/cefclient/extension_test.cpp index d8eb7a946..d1d03ae41 100644 --- a/cef1/tests/cefclient/extension_test.cpp +++ b/cef1/tests/cefclient/extension_test.cpp @@ -23,10 +23,7 @@ class ClientV8ExtensionHandler : public CefV8Handler { const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) { - if (name == "Dummy") { - // Used for performance testing. - return true; - } else if (name == "SetTestParam") { + if (name == "SetTestParam") { // Handle the SetTestParam native function by saving the string argument // into the local member. if (arguments.size() != 1 || !arguments[0]->IsString()) @@ -89,10 +86,6 @@ void InitExtensionTest() { " native function GetTestObject();" " return GetTestObject();" " };" - " cef.test.dummy = function() {" - " native function Dummy();" - " return Dummy();" - " };" "})();"; CefRegisterExtension("v8/test", code, new ClientV8ExtensionHandler()); } @@ -114,13 +107,3 @@ void RunExtensionTest(CefRefPtr browser) { ""; browser->GetMainFrame()->LoadString(html, "about:blank"); } - -void RunExtensionPerfTest(CefRefPtr browser) { - CefRefPtr resourceStream; -#if defined(OS_WIN) - resourceStream = GetBinaryResourceReader(IDS_EXTENSIONPERF); -#elif defined(OS_MACOSX) - resourceStream = GetBinaryResourceReader("extensionperf.html"); -#endif - browser->GetMainFrame()->LoadStream(resourceStream, "about:blank"); -} diff --git a/cef1/tests/cefclient/extension_test.h b/cef1/tests/cefclient/extension_test.h index d0a7e04be..6f328cdde 100644 --- a/cef1/tests/cefclient/extension_test.h +++ b/cef1/tests/cefclient/extension_test.h @@ -15,6 +15,5 @@ void InitExtensionTest(); // Run the test. void RunExtensionTest(CefRefPtr browser); -void RunExtensionPerfTest(CefRefPtr browser); #endif // CEF_TESTS_CEFCLIENT_EXTENSION_TEST_H_ diff --git a/cef1/tests/cefclient/performance_test.cpp b/cef1/tests/cefclient/performance_test.cpp new file mode 100644 index 000000000..e65aa1f8a --- /dev/null +++ b/cef1/tests/cefclient/performance_test.cpp @@ -0,0 +1,98 @@ +// 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. + +#include "cefclient/performance_test.h" +#include "include/cef_v8.h" + +#include +#include + +#include "cefclient/performance_test_setup.h" +#include "cefclient/resource_util.h" + +namespace performance_test { + +const size_t kDefaultIterations = 10000; +const char kTestUrl[] = "http://tests/performance"; + +namespace { + +const char kGetPerfTests[] = "GetPerfTests"; +const char kRunPerfTest[] = "RunPerfTest"; + +class V8Handler : public CefV8Handler { + public: + V8Handler() { + } + + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) { + if (name == kRunPerfTest) { + if (arguments.size() == 1 && arguments[0]->IsString()) { + // Run the specified perf test. + bool found = false; + + std::string test = arguments[0]->GetStringValue(); + for (size_t i = 0; i < kPerfTestsCount; ++i) { + if (test == kPerfTests[i].name) { + // Execute the test. + int64 delta = kPerfTests[i].test(kPerfTests[i].iterations); + + retval = CefV8Value::CreateInt(delta); + found = true; + break; + } + } + + if (!found) { + std::string msg = "Unknown test: "; + msg.append(test); + exception = msg; + } + } else { + exception = "Invalid function parameters"; + } + } else if (name == kGetPerfTests) { + // Retrieve the list of perf tests. + retval = CefV8Value::CreateArray(kPerfTestsCount); + for (size_t i = 0; i < kPerfTestsCount; ++i) { + CefRefPtr val = CefV8Value::CreateArray(2); + val->SetValue(0, CefV8Value::CreateString(kPerfTests[i].name)); + val->SetValue(1, CefV8Value::CreateUInt(kPerfTests[i].iterations)); + retval->SetValue(i, val); + } + } + + return true; + } + + private: + IMPLEMENT_REFCOUNTING(V8Handler); +}; + +} // namespace + +void InitTest(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr object) { + CefRefPtr handler = new V8Handler(); + + // Bind test functions. + object->SetValue(kGetPerfTests, + CefV8Value::CreateFunction(kGetPerfTests, handler), + V8_PROPERTY_ATTRIBUTE_READONLY); + object->SetValue(kRunPerfTest, + CefV8Value::CreateFunction(kRunPerfTest, handler), + V8_PROPERTY_ATTRIBUTE_READONLY); +} + +void RunTest(CefRefPtr browser) { + // Load the test URL. + browser->GetMainFrame()->LoadURL(kTestUrl); +} + +} // namespace performance_test diff --git a/cef1/tests/cefclient/performance_test.h b/cef1/tests/cefclient/performance_test.h new file mode 100644 index 000000000..a47f66987 --- /dev/null +++ b/cef1/tests/cefclient/performance_test.h @@ -0,0 +1,28 @@ +// 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. + +#ifndef CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_H_ +#define CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_H_ +#pragma once + +#include "include/cef_base.h" + +class CefBrowser; +class CefFrame; +class CefV8Value; + +namespace performance_test { + +extern const char kTestUrl[]; + +void InitTest(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr object); + +// Run the test. +void RunTest(CefRefPtr browser); + +} // namespace performance_test + +#endif // CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_H_ diff --git a/cef1/tests/cefclient/performance_test_setup.h b/cef1/tests/cefclient/performance_test_setup.h new file mode 100644 index 000000000..a4f2647ef --- /dev/null +++ b/cef1/tests/cefclient/performance_test_setup.h @@ -0,0 +1,99 @@ +// 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. + +#ifndef CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_SETUP_H_ +#define CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_SETUP_H_ +#pragma once + +#include "cefclient/util.h" + +namespace performance_test { + +// Default number of iterations. +extern const size_t kDefaultIterations; + +// Test name. +#define PERF_TEST_NAME(name) PerfTest##name + +// Entry in test array. +#define PERF_TEST_ENTRY_EX(name, iterations) \ + { #name, PERF_TEST_NAME(name), iterations } +#define PERF_TEST_ENTRY(name) PERF_TEST_ENTRY_EX(name, kDefaultIterations) + +// Test function declaration. +#define PERF_TEST_RESULT int64 +#define PERF_TEST_PARAM_ITERATIONS iterations +#define PERF_TEST_PARAMS size_t PERF_TEST_PARAM_ITERATIONS +#define PERF_TEST_FUNC(name) \ + PERF_TEST_RESULT PERF_TEST_NAME(name)(PERF_TEST_PARAMS) + +// Typedef for test pointers. +typedef PERF_TEST_RESULT(PerfTest(PERF_TEST_PARAMS)); + +class CefTimer { + public: + CefTimer() : running_(false) { + } + + bool IsRunning() { return running_; } + + void Start() { + ASSERT(!running_); + running_ = true; + start_.Now(); + } + + void Stop() { + stop_.Now(); + ASSERT(running_); + running_ = false; + } + + int64 Delta() { + ASSERT(!running_); + return start_.Delta(stop_); + } + + private: + bool running_; + CefTime start_; + CefTime stop_; +}; + +// Peform test iterations using a user-provided timing result variable. +#define PERF_ITERATIONS_START_EX() \ + { \ + CefTimer _timer; \ + _timer.Start(); \ + for (size_t _i = 0; _i < PERF_TEST_PARAM_ITERATIONS; ++_i) { + +#define PERF_ITERATIONS_END_EX(result) \ + } \ + _timer.Stop(); \ + result = _timer.Delta(); \ + } + +// Perform test iterations and return the timing result. +#define PERF_ITERATIONS_START() \ + int64 _result = 0; \ + PERF_ITERATIONS_START_EX() + +#define PERF_ITERATIONS_END() \ + PERF_ITERATIONS_END_EX(_result) \ + return _result; + +// Perf test entry structure. +struct PerfTestEntry { + const char* name; + PerfTest* test; + size_t iterations; +}; + +// Array of perf tests. +extern const PerfTestEntry kPerfTests[]; +extern const size_t kPerfTestsCount; + +} // namespace performance_test + +#endif // CEF_TESTS_CEFCLIENT_PERFORMANCE_TEST_H_ diff --git a/cef1/tests/cefclient/performance_test_tests.cpp b/cef1/tests/cefclient/performance_test_tests.cpp new file mode 100644 index 000000000..389a126a2 --- /dev/null +++ b/cef1/tests/cefclient/performance_test_tests.cpp @@ -0,0 +1,328 @@ +// 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. + +#include "cefclient/performance_test.h" +#include "cefclient/performance_test_setup.h" +#include "include/cef_v8.h" + +namespace performance_test { + +namespace { + +// Test function implementations. + +PERF_TEST_FUNC(V8NullCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateNull(); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8BoolCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateBool(true); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8IntCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateInt(-5); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8UIntCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateUInt(10); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8DoubleCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateDouble(12.432); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8DateCreate) { + static cef_time_t time = {2012, 1, 0, 1}; + + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateDate(time); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8StringCreate) { + CefString str = "test string"; + + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateString(str); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ArrayCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateArray(1); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ArraySetValue) { + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr array = CefV8Value::CreateArray(1); + array->SetValue(0, val); + + PERF_ITERATIONS_START() + array->SetValue(0, val); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ArrayGetValue) { + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr array = CefV8Value::CreateArray(1); + array->SetValue(0, val); + + PERF_ITERATIONS_START() + CefRefPtr ret = array->GetValue(0); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8FunctionCreate) { + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { return false; } + IMPLEMENT_REFCOUNTING(Handler); + }; + + CefString name = "name"; + CefRefPtr handler = new Handler(); + + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateFunction(name, handler); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8FunctionExecute) { + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { return true; } + IMPLEMENT_REFCOUNTING(Handler); + }; + + CefString name = "name"; + CefRefPtr handler = new Handler(); + CefRefPtr func = CefV8Value::CreateFunction(name, handler); + CefRefPtr obj = CefV8Context::GetCurrentContext()->GetGlobal(); + CefV8ValueList args; + + PERF_ITERATIONS_START() + func->ExecuteFunction(obj, args); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8FunctionExecuteWithContext) { + class Handler : public CefV8Handler { + public: + Handler() {} + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE { return true; } + IMPLEMENT_REFCOUNTING(Handler); + }; + + CefString name = "name"; + CefRefPtr handler = new Handler(); + CefRefPtr func = CefV8Value::CreateFunction(name, handler); + CefRefPtr context = CefV8Context::GetCurrentContext(); + CefRefPtr obj = context->GetGlobal(); + CefV8ValueList args; + + PERF_ITERATIONS_START() + func->ExecuteFunctionWithContext(context, obj, args); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ObjectCreate) { + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateObject(NULL); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ObjectCreateWithAccessor) { + class Accessor : public CefV8Accessor { + public: + Accessor() {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + return true; + } + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + return true; + } + IMPLEMENT_REFCOUNTING(Accessor); + }; + + CefRefPtr accessor = new Accessor(); + + PERF_ITERATIONS_START() + CefRefPtr value = CefV8Value::CreateObject(accessor); + PERF_ITERATIONS_END() +} + + +PERF_TEST_FUNC(V8ObjectSetValue) { + CefString name = "name"; + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr obj = CefV8Value::CreateObject(NULL); + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + + PERF_ITERATIONS_START() + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ObjectGetValue) { + CefString name = "name"; + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr obj = CefV8Value::CreateObject(NULL); + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + + PERF_ITERATIONS_START() + CefRefPtr ret = obj->GetValue(name); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ObjectSetValueWithAccessor) { + class Accessor : public CefV8Accessor { + public: + Accessor() {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + return true; + } + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + val_ = value; + return true; + } + CefRefPtr val_; + IMPLEMENT_REFCOUNTING(Accessor); + }; + + CefRefPtr accessor = new Accessor(); + + CefString name = "name"; + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr obj = CefV8Value::CreateObject(accessor); + obj->SetValue(name, V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + + PERF_ITERATIONS_START() + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ObjectGetValueWithAccessor) { + class Accessor : public CefV8Accessor { + public: + Accessor() : val_(CefV8Value::CreateBool(true)) {} + virtual bool Get(const CefString& name, + const CefRefPtr object, + CefRefPtr& retval, + CefString& exception) OVERRIDE { + retval = val_; + return true; + } + virtual bool Set(const CefString& name, + const CefRefPtr object, + const CefRefPtr value, + CefString& exception) OVERRIDE { + return true; + } + CefRefPtr val_; + IMPLEMENT_REFCOUNTING(Accessor); + }; + + CefRefPtr accessor = new Accessor(); + + CefString name = "name"; + CefRefPtr val = CefV8Value::CreateBool(true); + CefRefPtr obj = CefV8Value::CreateObject(accessor); + obj->SetValue(name, V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue(name, val, V8_PROPERTY_ATTRIBUTE_NONE); + + PERF_ITERATIONS_START() + CefRefPtr ret = obj->GetValue(name); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ContextEnterExit) { + CefRefPtr context = CefV8Context::GetCurrentContext(); + + PERF_ITERATIONS_START() + context->Enter(); + context->Exit(); + PERF_ITERATIONS_END() +} + +PERF_TEST_FUNC(V8ContextEval) { + CefRefPtr context = CefV8Context::GetCurrentContext(); + CefString jsCode = "var i = 0;"; + CefRefPtr retval; + CefRefPtr exception; + + PERF_ITERATIONS_START() + context->Eval(jsCode, retval, exception); + PERF_ITERATIONS_END() +} + +} // namespace + + +// Test function entries. + +const PerfTestEntry kPerfTests[] = { + PERF_TEST_ENTRY(V8NullCreate), + PERF_TEST_ENTRY(V8BoolCreate), + PERF_TEST_ENTRY(V8IntCreate), + PERF_TEST_ENTRY(V8UIntCreate), + PERF_TEST_ENTRY(V8DoubleCreate), + PERF_TEST_ENTRY(V8DateCreate), + PERF_TEST_ENTRY(V8StringCreate), + PERF_TEST_ENTRY(V8ArrayCreate), + PERF_TEST_ENTRY(V8ArraySetValue), + PERF_TEST_ENTRY(V8ArrayGetValue), + PERF_TEST_ENTRY(V8FunctionCreate), + PERF_TEST_ENTRY(V8FunctionExecute), + PERF_TEST_ENTRY(V8FunctionExecuteWithContext), + PERF_TEST_ENTRY(V8ObjectCreate), + PERF_TEST_ENTRY(V8ObjectCreateWithAccessor), + PERF_TEST_ENTRY(V8ObjectSetValue), + PERF_TEST_ENTRY(V8ObjectGetValue), + PERF_TEST_ENTRY(V8ObjectSetValueWithAccessor), + PERF_TEST_ENTRY(V8ObjectGetValueWithAccessor), + PERF_TEST_ENTRY(V8ContextEnterExit), + PERF_TEST_ENTRY(V8ContextEval), +}; + +const size_t kPerfTestsCount = (sizeof(kPerfTests) / sizeof(kPerfTests[0])); + +} // namespace performance_test diff --git a/cef1/tests/cefclient/res/extensionperf.html b/cef1/tests/cefclient/res/extensionperf.html deleted file mode 100644 index 5ac6e7925..000000000 --- a/cef1/tests/cefclient/res/extensionperf.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - JavaScript Extension: Performance - - - -

JavaScript Extension: Performance

- -
- -
- - - - - - - - - - - -
NameMinAvgMaxProbes
-
- - - - - diff --git a/cef1/tests/cefclient/res/performance.html b/cef1/tests/cefclient/res/performance.html new file mode 100644 index 000000000..df7f0a5d7 --- /dev/null +++ b/cef1/tests/cefclient/res/performance.html @@ -0,0 +1,293 @@ + + + + Performance Tests + + + +

Performance Tests

+ Filter: +
+ +
+ + + + + + + + + + + + + +
NameIterations per RunAvg (ms)Min (ms)Max (ms)StdDev (ms)Runs (ms)
+
+ +
+ + Result 1: +
Result 2: +
+ +
+ + + + + + + + + + +
NameResult 1 Avg (ms)Result 2 Avg (ms)% Diff
+
+ + + + + diff --git a/cef1/tests/cefclient/resource.h b/cef1/tests/cefclient/resource.h index 756a02c33..c6aad2a67 100644 --- a/cef1/tests/cefclient/resource.h +++ b/cef1/tests/cefclient/resource.h @@ -51,7 +51,7 @@ #define ID_TESTS_DRAGDROP 32792 #define ID_TESTS_OSRAPP 32793 #define ID_TESTS_MODALDIALOG 32794 -#define ID_TESTS_JAVASCRIPT_PERFORMANCE 32795 +#define ID_TESTS_PERFORMANCE 32795 #define ID_TESTS_TRANSPARENT_POPUP 32796 #define ID_TESTS_TRANSPARENT_OSRAPP 32797 #define ID_TESTS_JAVASCRIPT_INVOKE 32798 @@ -68,7 +68,7 @@ #define IDS_OSRPLUGIN 1006 #define IDS_MODALMAIN 1007 #define IDS_MODALDIALOG 1008 -#define IDS_EXTENSIONPERF 1009 +#define IDS_PERFORMANCE 1009 #define IDS_TRANSPARENCY 1010 // Avoid files associated with MacOS