Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/perftimer.h" | 6 #include "base/perftimer.h" |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "ppapi/c/ppp_messaging.h" | 8 #include "ppapi/c/ppp_messaging.h" |
| 9 #include "ppapi/proxy/ppapi_proxy_test.h" | 9 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 10 #include "ppapi/proxy/serialized_var.h" | 10 #include "ppapi/proxy/serialized_var.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 StringVar* string_var = StringVar::FromPPVar(message_data); | 22 StringVar* string_var = StringVar::FromPPVar(message_data); |
| 23 DCHECK(string_var); | 23 DCHECK(string_var); |
| 24 // Retrieve the string to make sure the proxy can't "optimize away" sending | 24 // Retrieve the string to make sure the proxy can't "optimize away" sending |
| 25 // the actual contents of the string (e.g., by doing a lazy retrieve or | 25 // the actual contents of the string (e.g., by doing a lazy retrieve or |
| 26 // something). Note that this test is for performance only, and assumes | 26 // something). Note that this test is for performance only, and assumes |
| 27 // other tests check for correctness. | 27 // other tests check for correctness. |
| 28 std::string s = string_var->value(); | 28 std::string s = string_var->value(); |
| 29 // Do something simple with the string so the compiler won't complain. | 29 // Do something simple with the string so the compiler won't complain. |
| 30 if (s.length() > 0) | 30 if (s.length() > 0) |
| 31 s[0] = 'a'; | 31 s[0] = 'a'; |
| 32 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(message_data); | |
| 32 handle_message_called.Signal(); | 33 handle_message_called.Signal(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 PPP_Messaging ppp_messaging_mock = { | 36 PPP_Messaging ppp_messaging_mock = { |
| 36 &HandleMessage | 37 &HandleMessage |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 class PppMessagingPerfTest : public TwoWayTest { | 40 class PppMessagingPerfTest : public TwoWayTest { |
| 40 public: | 41 public: |
| 41 PppMessagingPerfTest() : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 42 PppMessagingPerfTest() : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
| 42 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, | 43 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, |
| 43 &ppp_messaging_mock); | 44 &ppp_messaging_mock); |
| 44 } | 45 } |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 // Tests the performance of sending strings through the proxy. | 50 // Tests the performance of sending strings through the proxy. |
| 50 TEST_F(PppMessagingPerfTest, StringPerformance) { | 51 TEST_F(PppMessagingPerfTest, StringPerformance) { |
| 51 // Grab the host-side proxy of ppp_messaging. | 52 // Grab the host-side proxy of ppp_messaging. |
| 52 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( | 53 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( |
| 53 host().host_dispatcher()->GetProxiedInterface( | 54 host().host_dispatcher()->GetProxiedInterface( |
| 54 PPP_MESSAGING_INTERFACE)); | 55 PPP_MESSAGING_INTERFACE)); |
| 55 const PP_Instance kTestInstance = pp_instance(); | 56 const PP_Instance kTestInstance = pp_instance(); |
| 56 int string_size = 100000; | 57 int seed = 123; |
| 57 int string_count = 1000; | 58 int string_count = 1000; |
| 59 int max_string_size = 1000000; | |
| 58 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 59 if (command_line) { | 61 if (command_line) { |
| 60 if (command_line->HasSwitch("string_size")) { | 62 if (command_line->HasSwitch("seed")) { |
| 61 base::StringToInt(command_line->GetSwitchValueASCII("string_size"), | 63 base::StringToInt(command_line->GetSwitchValueASCII("seed"), |
| 62 &string_size); | 64 &seed); |
| 63 } | 65 } |
| 64 if (command_line->HasSwitch("string_count")) { | 66 if (command_line->HasSwitch("string_count")) { |
| 65 base::StringToInt(command_line->GetSwitchValueASCII("string_count"), | 67 base::StringToInt(command_line->GetSwitchValueASCII("string_count"), |
| 66 &string_count); | 68 &string_count); |
| 67 } | 69 } |
| 70 if (command_line->HasSwitch("max_string_size")) { | |
| 71 base::StringToInt(command_line->GetSwitchValueASCII("max_string_size"), | |
| 72 &max_string_size); | |
| 73 } | |
| 68 } | 74 } |
| 75 srand(seed); | |
| 69 // Make a string var of size string_size. | 76 // Make a string var of size string_size. |
|
bbudge
2012/02/03 19:51:30
This comment seems out of place.
| |
| 70 const std::string kTestString(string_size, 'a'); | |
| 71 PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance"); | 77 PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance"); |
| 72 for (int i = 0; i < string_count; ++i) { | 78 for (int i = 0; i < string_count; ++i) { |
| 73 PP_Var host_string = StringVar::StringToPPVar(kTestString); | 79 const std::string test_string(rand() % max_string_size, 'a'); |
| 80 PP_Var host_string = StringVar::StringToPPVar(test_string); | |
| 74 ppp_messaging->HandleMessage(kTestInstance, host_string); | 81 ppp_messaging->HandleMessage(kTestInstance, host_string); |
| 75 handle_message_called.Wait(); | 82 handle_message_called.Wait(); |
| 76 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(host_string); | 83 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(host_string); |
| 77 } | 84 } |
| 78 } | 85 } |
| 79 | 86 |
| 80 } // namespace proxy | 87 } // namespace proxy |
| 81 } // namespace ppapi | 88 } // namespace ppapi |
| 82 | 89 |
| OLD | NEW |