Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 | 6 |
| 7 #include "vm/benchmark_test.h" | 7 #include "vm/benchmark_test.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/stack_frame.h" | |
| 9 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| 10 | 11 |
| 11 namespace dart { | 12 namespace dart { |
| 12 | 13 |
| 13 Benchmark* Benchmark::first_ = NULL; | 14 Benchmark* Benchmark::first_ = NULL; |
| 14 Benchmark* Benchmark::tail_ = NULL; | 15 Benchmark* Benchmark::tail_ = NULL; |
| 15 | 16 |
| 16 void Benchmark::RunAll() { | 17 void Benchmark::RunAll() { |
| 17 Benchmark* benchmark = first_; | 18 Benchmark* benchmark = first_; |
| 18 while (benchmark != NULL) { | 19 while (benchmark != NULL) { |
| 19 benchmark->RunBenchmark(); | 20 benchmark->RunBenchmark(); |
| 20 benchmark = benchmark->next_; | 21 benchmark = benchmark->next_; |
| 21 } | 22 } |
| 22 } | 23 } |
| 23 | 24 |
| 24 | 25 |
| 25 // Compiler only implemented on IA32 and X64 now. | 26 // Compiler only implemented on IA32 and X64 now. |
| 26 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 27 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 27 | 28 |
| 29 | |
| 30 /* | |
|
cshapiro
2012/05/01 00:37:24
"// ..." comments instead of "/* ... */" for consi
siva
2012/05/01 00:59:48
Done.
| |
| 31 * Measure compile of all functions in dart core lib classes. | |
| 32 */ | |
| 28 BENCHMARK(CorelibCompileAll) { | 33 BENCHMARK(CorelibCompileAll) { |
| 29 Timer timer(true, "Compile all benchmark"); | 34 Timer timer(true, "Compile all of Core lib benchmark"); |
| 30 timer.Start(); | 35 timer.Start(); |
| 31 const Error& error = Error::Handle(benchmark->isolate(), | 36 const Error& error = Error::Handle(benchmark->isolate(), |
| 32 Library::CompileAll()); | 37 Library::CompileAll()); |
| 33 EXPECT(error.IsNull()); | 38 EXPECT(error.IsNull()); |
| 34 timer.Stop(); | 39 timer.Stop(); |
| 35 int64_t elapsed_time = timer.TotalElapsedTime(); | 40 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 36 benchmark->set_score(elapsed_time); | 41 benchmark->set_score(elapsed_time); |
| 37 } | 42 } |
| 38 | 43 |
| 39 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 | 44 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 |
| 40 | 45 |
| 41 | 46 |
| 47 /* | |
| 48 * Measure creation of core isolate from a snapshot. | |
| 49 */ | |
| 42 BENCHMARK(CorelibIsolateStartup) { | 50 BENCHMARK(CorelibIsolateStartup) { |
| 43 const int kNumIterations = 100; | 51 const int kNumIterations = 100; |
| 44 char* err = NULL; | 52 char* err = NULL; |
| 45 Dart_Isolate base_isolate = Dart_CurrentIsolate(); | 53 Dart_Isolate base_isolate = Dart_CurrentIsolate(); |
| 46 Dart_Isolate test_isolate = Dart_CreateIsolate(NULL, NULL, NULL, &err); | 54 Dart_Isolate test_isolate = Dart_CreateIsolate(NULL, NULL, NULL, &err); |
| 47 EXPECT(test_isolate != NULL); | 55 EXPECT(test_isolate != NULL); |
| 48 Dart_EnterScope(); | 56 Dart_EnterScope(); |
| 49 uint8_t* buffer = NULL; | 57 uint8_t* buffer = NULL; |
| 50 intptr_t size = 0; | 58 intptr_t size = 0; |
| 51 Dart_Handle result = Dart_CreateSnapshot(&buffer, &size); | 59 Dart_Handle result = Dart_CreateSnapshot(&buffer, &size); |
| 52 EXPECT(!Dart_IsError(result)); | 60 EXPECT(!Dart_IsError(result)); |
| 53 Timer timer(true, "Core Isolate startup benchmark"); | 61 Timer timer(true, "Core Isolate startup benchmark"); |
| 54 timer.Start(); | 62 timer.Start(); |
| 55 for (int i = 0; i < kNumIterations; i++) { | 63 for (int i = 0; i < kNumIterations; i++) { |
| 56 Dart_Isolate new_isolate = Dart_CreateIsolate(NULL, buffer, NULL, &err); | 64 Dart_Isolate new_isolate = Dart_CreateIsolate(NULL, buffer, NULL, &err); |
| 57 EXPECT(new_isolate != NULL); | 65 EXPECT(new_isolate != NULL); |
| 58 Dart_ShutdownIsolate(); | 66 Dart_ShutdownIsolate(); |
| 59 } | 67 } |
| 60 timer.Stop(); | 68 timer.Stop(); |
| 61 int64_t elapsed_time = timer.TotalElapsedTime(); | 69 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 62 benchmark->set_score(elapsed_time / kNumIterations); | 70 benchmark->set_score(elapsed_time / kNumIterations); |
| 63 Dart_EnterIsolate(test_isolate); | 71 Dart_EnterIsolate(test_isolate); |
| 64 Dart_ExitScope(); | 72 Dart_ExitScope(); |
| 65 Dart_ShutdownIsolate(); | 73 Dart_ShutdownIsolate(); |
| 66 Dart_EnterIsolate(base_isolate); | 74 Dart_EnterIsolate(base_isolate); |
| 67 } | 75 } |
| 68 | 76 |
| 69 | 77 |
| 70 void InitNativeFields(Dart_NativeArguments args) { | 78 /* |
| 79 * Measure invocation of Dart API functions. | |
| 80 */ | |
| 81 static void InitNativeFields(Dart_NativeArguments args) { | |
| 71 Dart_EnterScope(); | 82 Dart_EnterScope(); |
| 72 int count = Dart_GetNativeArgumentCount(args); | 83 int count = Dart_GetNativeArgumentCount(args); |
| 73 EXPECT_EQ(1, count); | 84 EXPECT_EQ(1, count); |
| 74 | 85 |
| 75 Dart_Handle recv = Dart_GetNativeArgument(args, 0); | 86 Dart_Handle recv = Dart_GetNativeArgument(args, 0); |
| 76 EXPECT(!Dart_IsError(recv)); | 87 EXPECT(!Dart_IsError(recv)); |
| 77 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7); | 88 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7); |
| 78 EXPECT(!Dart_IsError(result)); | 89 EXPECT(!Dart_IsError(result)); |
| 79 | 90 |
| 80 Dart_ExitScope(); | 91 Dart_ExitScope(); |
| 81 } | 92 } |
| 82 | 93 |
| 83 | 94 |
| 84 // The specific api functions called here are a bit arbitrary. We are | 95 // The specific api functions called here are a bit arbitrary. We are |
| 85 // trying to get a sense of the overhead for using the dart api. | 96 // trying to get a sense of the overhead for using the dart api. |
| 86 void UseDartApi(Dart_NativeArguments args) { | 97 static void UseDartApi(Dart_NativeArguments args) { |
| 87 Dart_EnterScope(); | 98 Dart_EnterScope(); |
| 88 int count = Dart_GetNativeArgumentCount(args); | 99 int count = Dart_GetNativeArgumentCount(args); |
| 89 EXPECT_EQ(3, count); | 100 EXPECT_EQ(3, count); |
| 90 | 101 |
| 91 // Get the receiver. | 102 // Get the receiver. |
| 92 Dart_Handle recv = Dart_GetNativeArgument(args, 0); | 103 Dart_Handle recv = Dart_GetNativeArgument(args, 0); |
| 93 EXPECT(!Dart_IsError(recv)); | 104 EXPECT(!Dart_IsError(recv)); |
| 94 | 105 |
| 95 // Get param1. | 106 // Get param1. |
| 96 Dart_Handle param1 = Dart_GetNativeArgument(args, 1); | 107 Dart_Handle param1 = Dart_GetNativeArgument(args, 1); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 args[0] = Dart_NewInteger(kNumIterations); | 173 args[0] = Dart_NewInteger(kNumIterations); |
| 163 Dart_Invoke(lib, | 174 Dart_Invoke(lib, |
| 164 Dart_NewString("benchmark"), | 175 Dart_NewString("benchmark"), |
| 165 1, | 176 1, |
| 166 args); | 177 args); |
| 167 timer.Stop(); | 178 timer.Stop(); |
| 168 int64_t elapsed_time = timer.TotalElapsedTime(); | 179 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 169 benchmark->set_score(elapsed_time); | 180 benchmark->set_score(elapsed_time); |
| 170 } | 181 } |
| 171 | 182 |
| 183 | |
| 184 /* | |
| 185 * Measure compile of all dart2js(compiler) functions. | |
| 186 */ | |
| 187 static void func(Dart_NativeArguments args) { | |
| 188 } | |
| 189 | |
| 190 | |
| 191 static Dart_NativeFunction NativeResolver(Dart_Handle name, | |
| 192 int arg_count) { | |
| 193 return &func; | |
| 194 } | |
| 195 | |
| 196 | |
| 197 BENCHMARK(Dart2JSCompileAll) { | |
| 198 const char* kScriptChars = "#import('../lib/compiler/compiler.dart');"; | |
| 199 Dart_Handle lib = TestCase::LoadTestScript( | |
| 200 kScriptChars, | |
| 201 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | |
| 202 EXPECT(!Dart_IsError(lib)); | |
| 203 Timer timer(true, "Compile all of dart2js benchmark"); | |
| 204 timer.Start(); | |
| 205 Dart_Handle result = Dart_CompileAll(); | |
| 206 EXPECT(!Dart_IsError(result)); | |
| 207 timer.Stop(); | |
| 208 int64_t elapsed_time = timer.TotalElapsedTime(); | |
| 209 benchmark->set_score(elapsed_time); | |
| 210 } | |
| 211 | |
| 212 | |
| 213 /* | |
| 214 * Measure frame lookup during stack traversal. | |
| 215 */ | |
| 216 static void StackFrame_accessFrame(Dart_NativeArguments args) { | |
| 217 const int kNumIterations = 100; | |
| 218 Dart_EnterScope(); | |
| 219 Code& code = Code::Handle(); | |
| 220 Timer timer(true, "LookupDartCode benchmark"); | |
| 221 timer.Start(); | |
| 222 for (int i = 0; i < kNumIterations; i++) { | |
| 223 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | |
| 224 StackFrame* frame = frames.NextFrame(); | |
| 225 while (frame != NULL) { | |
| 226 if (frame->IsStubFrame()) { | |
| 227 code ^= frame->LookupDartCode(); | |
| 228 EXPECT(code.function() == Function::null()); | |
| 229 } else if (frame->IsDartFrame()) { | |
| 230 code ^= frame->LookupDartCode(); | |
| 231 EXPECT(code.function() != Function::null()); | |
| 232 } | |
| 233 frame = frames.NextFrame(); | |
| 234 } | |
| 235 } | |
| 236 timer.Stop(); | |
| 237 int64_t elapsed_time = timer.TotalElapsedTime(); | |
| 238 Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time)); | |
| 239 Dart_ExitScope(); | |
| 240 } | |
| 241 | |
| 242 | |
| 243 static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name, | |
| 244 int arg_count) { | |
| 245 return &StackFrame_accessFrame; | |
| 246 } | |
| 247 | |
| 248 | |
| 249 // Unit test case to verify stack frame iteration. | |
| 250 BENCHMARK(FrameLookup) { | |
| 251 const char* kScriptChars = | |
| 252 "class StackFrame {" | |
| 253 " static int accessFrame() native \"StackFrame_accessFrame\";" | |
| 254 "} " | |
| 255 "class First {" | |
| 256 " First() { }" | |
| 257 " int method1(int param) {" | |
| 258 " if (param == 1) {" | |
| 259 " param = method2(200);" | |
| 260 " } else {" | |
| 261 " param = method2(100);" | |
| 262 " }" | |
| 263 " return param;" | |
| 264 " }" | |
| 265 " int method2(int param) {" | |
| 266 " if (param == 200) {" | |
| 267 " return First.staticmethod(this, param);" | |
| 268 " } else {" | |
| 269 " return First.staticmethod(this, 10);" | |
| 270 " }" | |
| 271 " }" | |
| 272 " static int staticmethod(First obj, int param) {" | |
| 273 " if (param == 10) {" | |
| 274 " return obj.method3(10);" | |
| 275 " } else {" | |
| 276 " return obj.method3(200);" | |
| 277 " }" | |
| 278 " }" | |
| 279 " int method3(int param) {" | |
| 280 " return StackFrame.accessFrame();" | |
| 281 " }" | |
| 282 "}" | |
| 283 "class StackFrameTest {" | |
| 284 " static int testMain() {" | |
| 285 " First obj = new First();" | |
| 286 " return obj.method1(1);" | |
| 287 " }" | |
| 288 "}"; | |
| 289 Dart_Handle lib = TestCase::LoadTestScript( | |
| 290 kScriptChars, | |
| 291 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); | |
| 292 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); | |
| 293 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | |
| 294 EXPECT_VALID(result); | |
| 295 int64_t elapsed_time = 0; | |
| 296 EXPECT(!Dart_IsError(Dart_IntegerToInt64(result, &elapsed_time))); | |
| 297 benchmark->set_score(elapsed_time); | |
| 298 } | |
| 299 | |
| 172 } // namespace dart | 300 } // namespace dart |
| OLD | NEW |