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 "vm/benchmark_test.h" | 5 #include "vm/benchmark_test.h" |
6 | 6 |
7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 #include "bin/isolate_data.h" | 9 #include "bin/isolate_data.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 Benchmark* Benchmark::tail_ = NULL; | 25 Benchmark* Benchmark::tail_ = NULL; |
26 const char* Benchmark::executable_ = NULL; | 26 const char* Benchmark::executable_ = NULL; |
27 | 27 |
28 | 28 |
29 // | 29 // |
30 // Measure compile of all dart2js(compiler) functions. | 30 // Measure compile of all dart2js(compiler) functions. |
31 // | 31 // |
32 static char* ComputeDart2JSPath(const char* arg) { | 32 static char* ComputeDart2JSPath(const char* arg) { |
33 char buffer[2048]; | 33 char buffer[2048]; |
34 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); | 34 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); |
35 const char* compiler_path = | 35 const char* compiler_path = "%s%spkg%scompiler%slib%scompiler.dart"; |
36 "%s%spkg%scompiler%slib%scompiler.dart"; | |
37 const char* path_separator = File::PathSeparator(); | 36 const char* path_separator = File::PathSeparator(); |
38 ASSERT(path_separator != NULL && strlen(path_separator) == 1); | 37 ASSERT(path_separator != NULL && strlen(path_separator) == 1); |
39 char* ptr = strrchr(dart2js_path, *path_separator); | 38 char* ptr = strrchr(dart2js_path, *path_separator); |
40 while (ptr != NULL) { | 39 while (ptr != NULL) { |
41 *ptr = '\0'; | 40 *ptr = '\0'; |
42 OS::SNPrint(buffer, 2048, compiler_path, | 41 OS::SNPrint(buffer, 2048, compiler_path, dart2js_path, path_separator, |
43 dart2js_path, | 42 path_separator, path_separator, path_separator, path_separator); |
44 path_separator, | |
45 path_separator, | |
46 path_separator, | |
47 path_separator, | |
48 path_separator); | |
49 if (File::Exists(buffer)) { | 43 if (File::Exists(buffer)) { |
50 break; | 44 break; |
51 } | 45 } |
52 ptr = strrchr(dart2js_path, *path_separator); | 46 ptr = strrchr(dart2js_path, *path_separator); |
53 } | 47 } |
54 if (ptr == NULL) { | 48 if (ptr == NULL) { |
55 free(dart2js_path); | 49 free(dart2js_path); |
56 dart2js_path = NULL; | 50 dart2js_path = NULL; |
57 } | 51 } |
58 return dart2js_path; | 52 return dart2js_path; |
59 } | 53 } |
60 | 54 |
61 | 55 |
62 static void func(Dart_NativeArguments args) { | 56 static void func(Dart_NativeArguments args) {} |
63 } | |
64 | 57 |
65 | 58 |
66 static Dart_NativeFunction NativeResolver(Dart_Handle name, | 59 static Dart_NativeFunction NativeResolver(Dart_Handle name, |
67 int arg_count, | 60 int arg_count, |
68 bool* auto_setup_scope) { | 61 bool* auto_setup_scope) { |
69 ASSERT(auto_setup_scope != NULL); | 62 ASSERT(auto_setup_scope != NULL); |
70 *auto_setup_scope = false; | 63 *auto_setup_scope = false; |
71 return &func; | 64 return &func; |
72 } | 65 } |
73 | 66 |
74 | 67 |
75 static void SetupDart2JSPackagePath() { | 68 static void SetupDart2JSPackagePath() { |
76 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); | 69 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); |
77 EXPECT(worked); | 70 EXPECT(worked); |
78 | 71 |
79 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false); | 72 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false); |
80 DART_CHECK_VALID(result); | 73 DART_CHECK_VALID(result); |
81 | 74 |
82 // Setup package root. | 75 // Setup package root. |
83 char buffer[2048]; | 76 char buffer[2048]; |
84 char* executable_path = | 77 char* executable_path = |
85 strdup(File::GetCanonicalPath(Benchmark::Executable())); | 78 strdup(File::GetCanonicalPath(Benchmark::Executable())); |
86 const char* packages_path = "%s%s..%spackages"; | 79 const char* packages_path = "%s%s..%spackages"; |
87 const char* path_separator = File::PathSeparator(); | 80 const char* path_separator = File::PathSeparator(); |
88 OS::SNPrint(buffer, 2048, packages_path, | 81 OS::SNPrint(buffer, 2048, packages_path, executable_path, path_separator, |
89 executable_path, path_separator, path_separator); | 82 path_separator); |
90 result = bin::DartUtils::SetupPackageRoot(buffer, NULL); | 83 result = bin::DartUtils::SetupPackageRoot(buffer, NULL); |
91 DART_CHECK_VALID(result); | 84 DART_CHECK_VALID(result); |
92 } | 85 } |
93 | 86 |
94 | 87 |
95 void Benchmark::RunAll(const char* executable) { | 88 void Benchmark::RunAll(const char* executable) { |
96 SetExecutable(executable); | 89 SetExecutable(executable); |
97 Benchmark* benchmark = first_; | 90 Benchmark* benchmark = first_; |
98 while (benchmark != NULL) { | 91 while (benchmark != NULL) { |
99 benchmark->RunBenchmark(); | 92 benchmark->RunBenchmark(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 149 |
157 | 150 |
158 BENCHMARK(Dart2JSCompilerStats) { | 151 BENCHMARK(Dart2JSCompilerStats) { |
159 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 152 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
160 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 153 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
161 SetupDart2JSPackagePath(); | 154 SetupDart2JSPackagePath(); |
162 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 155 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
163 char* script = NULL; | 156 char* script = NULL; |
164 if (dart_root != NULL) { | 157 if (dart_root != NULL) { |
165 HANDLESCOPE(thread); | 158 HANDLESCOPE(thread); |
166 script = OS::SCreate(NULL, | 159 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", |
167 "import '%s/pkg/compiler/lib/compiler.dart';", dart_root); | 160 dart_root); |
168 Dart_Handle lib = TestCase::LoadTestScript( | 161 Dart_Handle lib = TestCase::LoadTestScript( |
169 script, | 162 script, reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
170 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | |
171 EXPECT_VALID(lib); | 163 EXPECT_VALID(lib); |
172 } else { | 164 } else { |
173 Dart_Handle lib = TestCase::LoadTestScript( | 165 Dart_Handle lib = TestCase::LoadTestScript( |
174 "import 'pkg/compiler/lib/compiler.dart';", | 166 "import 'pkg/compiler/lib/compiler.dart';", |
175 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | 167 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
176 EXPECT_VALID(lib); | 168 EXPECT_VALID(lib); |
177 } | 169 } |
178 CompilerStats* stats = thread->isolate()->aggregate_compiler_stats(); | 170 CompilerStats* stats = thread->isolate()->aggregate_compiler_stats(); |
179 ASSERT(stats != NULL); | 171 ASSERT(stats != NULL); |
180 stats->EnableBenchmark(); | 172 stats->EnableBenchmark(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 "\n" | 286 "\n" |
295 "void benchmark(int count) {\n" | 287 "void benchmark(int count) {\n" |
296 " Class c = new Class();\n" | 288 " Class c = new Class();\n" |
297 " c.init();\n" | 289 " c.init();\n" |
298 " for (int i = 0; i < count; i++) {\n" | 290 " for (int i = 0; i < count; i++) {\n" |
299 " c.method(i,7);\n" | 291 " c.method(i,7);\n" |
300 " }\n" | 292 " }\n" |
301 "}\n"; | 293 "}\n"; |
302 | 294 |
303 Dart_Handle lib = TestCase::LoadTestScript( | 295 Dart_Handle lib = TestCase::LoadTestScript( |
304 kScriptChars, | 296 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup), |
305 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup), | 297 USER_TEST_URI, false); |
306 USER_TEST_URI, | |
307 false); | |
308 | 298 |
309 // Create a native wrapper class with native fields. | 299 // Create a native wrapper class with native fields. |
310 Dart_Handle result = Dart_CreateNativeWrapperClass( | 300 Dart_Handle result = |
311 lib, NewString("NativeFieldsWrapper"), 1); | 301 Dart_CreateNativeWrapperClass(lib, NewString("NativeFieldsWrapper"), 1); |
312 EXPECT_VALID(result); | 302 EXPECT_VALID(result); |
313 result = Dart_FinalizeLoading(false); | 303 result = Dart_FinalizeLoading(false); |
314 EXPECT_VALID(result); | 304 EXPECT_VALID(result); |
315 | 305 |
316 Dart_Handle args[1]; | 306 Dart_Handle args[1]; |
317 args[0] = Dart_NewInteger(kNumIterations); | 307 args[0] = Dart_NewInteger(kNumIterations); |
318 | 308 |
319 // Warmup first to avoid compilation jitters. | 309 // Warmup first to avoid compilation jitters. |
320 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 310 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
321 | 311 |
322 Timer timer(true, "UseDartApi benchmark"); | 312 Timer timer(true, "UseDartApi benchmark"); |
323 timer.Start(); | 313 timer.Start(); |
324 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 314 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
325 timer.Stop(); | 315 timer.Stop(); |
326 int64_t elapsed_time = timer.TotalElapsedTime(); | 316 int64_t elapsed_time = timer.TotalElapsedTime(); |
327 benchmark->set_score(elapsed_time); | 317 benchmark->set_score(elapsed_time); |
328 } | 318 } |
329 | 319 |
330 | 320 |
331 // | 321 // |
332 // Measure time accessing internal and external strings. | 322 // Measure time accessing internal and external strings. |
333 // | 323 // |
334 BENCHMARK(DartStringAccess) { | 324 BENCHMARK(DartStringAccess) { |
335 const int kNumIterations = 10000000; | 325 const int kNumIterations = 10000000; |
336 Timer timer(true, "DartStringAccess benchmark"); | 326 Timer timer(true, "DartStringAccess benchmark"); |
337 timer.Start(); | 327 timer.Start(); |
338 Dart_EnterScope(); | 328 Dart_EnterScope(); |
339 | 329 |
340 // Create strings. | 330 // Create strings. |
341 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; | 331 uint8_t data8[] = {'o', 'n', 'e', 0xFF}; |
342 int external_peer_data = 123; | 332 int external_peer_data = 123; |
343 intptr_t char_size; | 333 intptr_t char_size; |
344 intptr_t str_len; | 334 intptr_t str_len; |
345 Dart_Handle external_string = Dart_NewExternalLatin1String( | 335 Dart_Handle external_string = Dart_NewExternalLatin1String( |
346 data8, ARRAY_SIZE(data8), &external_peer_data, NULL); | 336 data8, ARRAY_SIZE(data8), &external_peer_data, NULL); |
347 Dart_Handle internal_string = NewString("two"); | 337 Dart_Handle internal_string = NewString("two"); |
348 | 338 |
349 // Run benchmark. | 339 // Run benchmark. |
350 for (int64_t i = 0; i < kNumIterations; i++) { | 340 for (int64_t i = 0; i < kNumIterations; i++) { |
351 EXPECT(Dart_IsString(internal_string)); | 341 EXPECT(Dart_IsString(internal_string)); |
352 EXPECT(!Dart_IsExternalString(internal_string)); | 342 EXPECT(!Dart_IsExternalString(internal_string)); |
353 EXPECT_VALID(external_string); | 343 EXPECT_VALID(external_string); |
354 EXPECT(Dart_IsExternalString(external_string)); | 344 EXPECT(Dart_IsExternalString(external_string)); |
355 void* external_peer = NULL; | 345 void* external_peer = NULL; |
356 EXPECT_VALID(Dart_StringGetProperties(external_string, | 346 EXPECT_VALID(Dart_StringGetProperties(external_string, &char_size, &str_len, |
357 &char_size, | |
358 &str_len, | |
359 &external_peer)); | 347 &external_peer)); |
360 EXPECT_EQ(1, char_size); | 348 EXPECT_EQ(1, char_size); |
361 EXPECT_EQ(4, str_len); | 349 EXPECT_EQ(4, str_len); |
362 EXPECT_EQ(&external_peer_data, external_peer); | 350 EXPECT_EQ(&external_peer_data, external_peer); |
363 } | 351 } |
364 | 352 |
365 Dart_ExitScope(); | 353 Dart_ExitScope(); |
366 timer.Stop(); | 354 timer.Stop(); |
367 int64_t elapsed_time = timer.TotalElapsedTime(); | 355 int64_t elapsed_time = timer.TotalElapsedTime(); |
368 benchmark->set_score(elapsed_time); | 356 benchmark->set_score(elapsed_time); |
369 } | 357 } |
370 | 358 |
371 | 359 |
372 BENCHMARK(Dart2JSCompileAll) { | 360 BENCHMARK(Dart2JSCompileAll) { |
373 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 361 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
374 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 362 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
375 SetupDart2JSPackagePath(); | 363 SetupDart2JSPackagePath(); |
376 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 364 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
377 char* script = NULL; | 365 char* script = NULL; |
378 if (dart_root != NULL) { | 366 if (dart_root != NULL) { |
379 HANDLESCOPE(thread); | 367 HANDLESCOPE(thread); |
380 script = OS::SCreate(NULL, | 368 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", |
381 "import '%s/pkg/compiler/lib/compiler.dart';", dart_root); | 369 dart_root); |
382 Dart_Handle lib = TestCase::LoadTestScript( | 370 Dart_Handle lib = TestCase::LoadTestScript( |
383 script, | 371 script, reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
384 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | |
385 EXPECT_VALID(lib); | 372 EXPECT_VALID(lib); |
386 } else { | 373 } else { |
387 Dart_Handle lib = TestCase::LoadTestScript( | 374 Dart_Handle lib = TestCase::LoadTestScript( |
388 "import 'pkg/compiler/lib/compiler.dart';", | 375 "import 'pkg/compiler/lib/compiler.dart';", |
389 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | 376 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
390 EXPECT_VALID(lib); | 377 EXPECT_VALID(lib); |
391 } | 378 } |
392 Timer timer(true, "Compile all of dart2js benchmark"); | 379 Timer timer(true, "Compile all of dart2js benchmark"); |
393 timer.Start(); | 380 timer.Start(); |
394 #if !defined(PRODUCT) | 381 #if !defined(PRODUCT) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); | 478 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); |
492 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 479 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
493 EXPECT_VALID(result); | 480 EXPECT_VALID(result); |
494 int64_t elapsed_time = 0; | 481 int64_t elapsed_time = 0; |
495 result = Dart_IntegerToInt64(result, &elapsed_time); | 482 result = Dart_IntegerToInt64(result, &elapsed_time); |
496 EXPECT_VALID(result); | 483 EXPECT_VALID(result); |
497 benchmark->set_score(elapsed_time); | 484 benchmark->set_score(elapsed_time); |
498 } | 485 } |
499 | 486 |
500 | 487 |
501 static uint8_t* malloc_allocator( | 488 static uint8_t* malloc_allocator(uint8_t* ptr, |
502 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 489 intptr_t old_size, |
| 490 intptr_t new_size) { |
503 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); | 491 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); |
504 } | 492 } |
505 | 493 |
506 | 494 |
507 BENCHMARK_SIZE(CoreSnapshotSize) { | 495 BENCHMARK_SIZE(CoreSnapshotSize) { |
508 const char* kScriptChars = | 496 const char* kScriptChars = |
509 "import 'dart:async';\n" | 497 "import 'dart:async';\n" |
510 "import 'dart:core';\n" | 498 "import 'dart:core';\n" |
511 "import 'dart:collection';\n" | 499 "import 'dart:collection';\n" |
512 "import 'dart:_internal';\n" | 500 "import 'dart:_internal';\n" |
513 "import 'dart:math';\n" | 501 "import 'dart:math';\n" |
514 "import 'dart:isolate';\n" | 502 "import 'dart:isolate';\n" |
515 "import 'dart:mirrors';\n" | 503 "import 'dart:mirrors';\n" |
516 "import 'dart:typed_data';\n" | 504 "import 'dart:typed_data';\n" |
517 "\n"; | 505 "\n"; |
518 | 506 |
519 // Start an Isolate, load a script and create a full snapshot. | 507 // Start an Isolate, load a script and create a full snapshot. |
520 uint8_t* vm_isolate_snapshot_buffer; | 508 uint8_t* vm_isolate_snapshot_buffer; |
521 uint8_t* isolate_snapshot_buffer; | 509 uint8_t* isolate_snapshot_buffer; |
522 // Need to load the script into the dart: core library due to | 510 // Need to load the script into the dart: core library due to |
523 // the import of dart:_internal. | 511 // the import of dart:_internal. |
524 TestCase::LoadCoreTestScript(kScriptChars, NULL); | 512 TestCase::LoadCoreTestScript(kScriptChars, NULL); |
525 Api::CheckAndFinalizePendingClasses(thread); | 513 Api::CheckAndFinalizePendingClasses(thread); |
526 | 514 |
527 // Write snapshot with object content. | 515 // Write snapshot with object content. |
528 FullSnapshotWriter writer(Snapshot::kCore, | 516 FullSnapshotWriter writer(Snapshot::kCore, &vm_isolate_snapshot_buffer, |
529 &vm_isolate_snapshot_buffer, | 517 &isolate_snapshot_buffer, &malloc_allocator, |
530 &isolate_snapshot_buffer, | |
531 &malloc_allocator, | |
532 NULL /* instructions_writer */); | 518 NULL /* instructions_writer */); |
533 writer.WriteFullSnapshot(); | 519 writer.WriteFullSnapshot(); |
534 const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer); | 520 const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer); |
535 ASSERT(snapshot->kind() == Snapshot::kCore); | 521 ASSERT(snapshot->kind() == Snapshot::kCore); |
536 benchmark->set_score(snapshot->length()); | 522 benchmark->set_score(snapshot->length()); |
537 } | 523 } |
538 | 524 |
539 | 525 |
540 BENCHMARK_SIZE(StandaloneSnapshotSize) { | 526 BENCHMARK_SIZE(StandaloneSnapshotSize) { |
541 const char* kScriptChars = | 527 const char* kScriptChars = |
(...skipping 12 matching lines...) Expand all Loading... |
554 | 540 |
555 // Start an Isolate, load a script and create a full snapshot. | 541 // Start an Isolate, load a script and create a full snapshot. |
556 uint8_t* vm_isolate_snapshot_buffer; | 542 uint8_t* vm_isolate_snapshot_buffer; |
557 uint8_t* isolate_snapshot_buffer; | 543 uint8_t* isolate_snapshot_buffer; |
558 // Need to load the script into the dart: core library due to | 544 // Need to load the script into the dart: core library due to |
559 // the import of dart:_internal. | 545 // the import of dart:_internal. |
560 TestCase::LoadCoreTestScript(kScriptChars, NULL); | 546 TestCase::LoadCoreTestScript(kScriptChars, NULL); |
561 Api::CheckAndFinalizePendingClasses(thread); | 547 Api::CheckAndFinalizePendingClasses(thread); |
562 | 548 |
563 // Write snapshot with object content. | 549 // Write snapshot with object content. |
564 FullSnapshotWriter writer(Snapshot::kCore, | 550 FullSnapshotWriter writer(Snapshot::kCore, &vm_isolate_snapshot_buffer, |
565 &vm_isolate_snapshot_buffer, | 551 &isolate_snapshot_buffer, &malloc_allocator, |
566 &isolate_snapshot_buffer, | |
567 &malloc_allocator, | |
568 NULL /* instructions_writer */); | 552 NULL /* instructions_writer */); |
569 writer.WriteFullSnapshot(); | 553 writer.WriteFullSnapshot(); |
570 const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer); | 554 const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer); |
571 ASSERT(snapshot->kind() == Snapshot::kCore); | 555 ASSERT(snapshot->kind() == Snapshot::kCore); |
572 benchmark->set_score(snapshot->length()); | 556 benchmark->set_score(snapshot->length()); |
573 } | 557 } |
574 | 558 |
575 | 559 |
576 BENCHMARK(CreateMirrorSystem) { | 560 BENCHMARK(CreateMirrorSystem) { |
577 const char* kScriptChars = | 561 const char* kScriptChars = |
(...skipping 28 matching lines...) Expand all Loading... |
606 Dart_ExitIsolate(); | 590 Dart_ExitIsolate(); |
607 Dart_EnterIsolate(isolate); | 591 Dart_EnterIsolate(isolate); |
608 } | 592 } |
609 timer.Stop(); | 593 timer.Stop(); |
610 int64_t elapsed_time = timer.TotalElapsedTime(); | 594 int64_t elapsed_time = timer.TotalElapsedTime(); |
611 benchmark->set_score(elapsed_time); | 595 benchmark->set_score(elapsed_time); |
612 } | 596 } |
613 | 597 |
614 | 598 |
615 static uint8_t message_buffer[64]; | 599 static uint8_t message_buffer[64]; |
616 static uint8_t* message_allocator( | 600 static uint8_t* message_allocator(uint8_t* ptr, |
617 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 601 intptr_t old_size, |
| 602 intptr_t new_size) { |
618 return message_buffer; | 603 return message_buffer; |
619 } | 604 } |
620 | 605 |
621 | 606 |
622 BENCHMARK(SerializeNull) { | 607 BENCHMARK(SerializeNull) { |
623 const Object& null_object = Object::Handle(); | 608 const Object& null_object = Object::Handle(); |
624 const intptr_t kLoopCount = 1000000; | 609 const intptr_t kLoopCount = 1000000; |
625 uint8_t* buffer; | 610 uint8_t* buffer; |
626 Timer timer(true, "Serialize Null"); | 611 Timer timer(true, "Serialize Null"); |
627 timer.Start(); | 612 timer.Start(); |
628 for (intptr_t i = 0; i < kLoopCount; i++) { | 613 for (intptr_t i = 0; i < kLoopCount; i++) { |
629 StackZone zone(thread); | 614 StackZone zone(thread); |
630 MessageWriter writer(&buffer, &message_allocator, true); | 615 MessageWriter writer(&buffer, &message_allocator, true); |
631 writer.WriteMessage(null_object); | 616 writer.WriteMessage(null_object); |
632 intptr_t buffer_len = writer.BytesWritten(); | 617 intptr_t buffer_len = writer.BytesWritten(); |
633 | 618 |
634 // Read object back from the snapshot. | 619 // Read object back from the snapshot. |
635 MessageSnapshotReader reader(buffer, | 620 MessageSnapshotReader reader(buffer, buffer_len, thread); |
636 buffer_len, | |
637 thread); | |
638 reader.ReadObject(); | 621 reader.ReadObject(); |
639 } | 622 } |
640 timer.Stop(); | 623 timer.Stop(); |
641 int64_t elapsed_time = timer.TotalElapsedTime(); | 624 int64_t elapsed_time = timer.TotalElapsedTime(); |
642 benchmark->set_score(elapsed_time); | 625 benchmark->set_score(elapsed_time); |
643 } | 626 } |
644 | 627 |
645 | 628 |
646 BENCHMARK(SerializeSmi) { | 629 BENCHMARK(SerializeSmi) { |
647 const Integer& smi_object = Integer::Handle(Smi::New(42)); | 630 const Integer& smi_object = Integer::Handle(Smi::New(42)); |
648 const intptr_t kLoopCount = 1000000; | 631 const intptr_t kLoopCount = 1000000; |
649 uint8_t* buffer; | 632 uint8_t* buffer; |
650 Timer timer(true, "Serialize Smi"); | 633 Timer timer(true, "Serialize Smi"); |
651 timer.Start(); | 634 timer.Start(); |
652 for (intptr_t i = 0; i < kLoopCount; i++) { | 635 for (intptr_t i = 0; i < kLoopCount; i++) { |
653 StackZone zone(thread); | 636 StackZone zone(thread); |
654 MessageWriter writer(&buffer, &message_allocator, true); | 637 MessageWriter writer(&buffer, &message_allocator, true); |
655 writer.WriteMessage(smi_object); | 638 writer.WriteMessage(smi_object); |
656 intptr_t buffer_len = writer.BytesWritten(); | 639 intptr_t buffer_len = writer.BytesWritten(); |
657 | 640 |
658 // Read object back from the snapshot. | 641 // Read object back from the snapshot. |
659 MessageSnapshotReader reader(buffer, | 642 MessageSnapshotReader reader(buffer, buffer_len, thread); |
660 buffer_len, | |
661 thread); | |
662 reader.ReadObject(); | 643 reader.ReadObject(); |
663 } | 644 } |
664 timer.Stop(); | 645 timer.Stop(); |
665 int64_t elapsed_time = timer.TotalElapsedTime(); | 646 int64_t elapsed_time = timer.TotalElapsedTime(); |
666 benchmark->set_score(elapsed_time); | 647 benchmark->set_score(elapsed_time); |
667 } | 648 } |
668 | 649 |
669 | 650 |
670 BENCHMARK(SimpleMessage) { | 651 BENCHMARK(SimpleMessage) { |
671 TransitionNativeToVM transition(thread); | 652 TransitionNativeToVM transition(thread); |
672 const Array& array_object = Array::Handle(Array::New(2)); | 653 const Array& array_object = Array::Handle(Array::New(2)); |
673 array_object.SetAt(0, Integer::Handle(Smi::New(42))); | 654 array_object.SetAt(0, Integer::Handle(Smi::New(42))); |
674 array_object.SetAt(1, Object::Handle()); | 655 array_object.SetAt(1, Object::Handle()); |
675 const intptr_t kLoopCount = 1000000; | 656 const intptr_t kLoopCount = 1000000; |
676 uint8_t* buffer; | 657 uint8_t* buffer; |
677 Timer timer(true, "Simple Message"); | 658 Timer timer(true, "Simple Message"); |
678 timer.Start(); | 659 timer.Start(); |
679 for (intptr_t i = 0; i < kLoopCount; i++) { | 660 for (intptr_t i = 0; i < kLoopCount; i++) { |
680 StackZone zone(thread); | 661 StackZone zone(thread); |
681 MessageWriter writer(&buffer, &malloc_allocator, true); | 662 MessageWriter writer(&buffer, &malloc_allocator, true); |
682 writer.WriteMessage(array_object); | 663 writer.WriteMessage(array_object); |
683 intptr_t buffer_len = writer.BytesWritten(); | 664 intptr_t buffer_len = writer.BytesWritten(); |
684 | 665 |
685 // Read object back from the snapshot. | 666 // Read object back from the snapshot. |
686 MessageSnapshotReader reader(buffer, | 667 MessageSnapshotReader reader(buffer, buffer_len, thread); |
687 buffer_len, | |
688 thread); | |
689 reader.ReadObject(); | 668 reader.ReadObject(); |
690 free(buffer); | 669 free(buffer); |
691 } | 670 } |
692 timer.Stop(); | 671 timer.Stop(); |
693 int64_t elapsed_time = timer.TotalElapsedTime(); | 672 int64_t elapsed_time = timer.TotalElapsedTime(); |
694 benchmark->set_score(elapsed_time); | 673 benchmark->set_score(elapsed_time); |
695 } | 674 } |
696 | 675 |
697 | 676 |
698 BENCHMARK(LargeMap) { | 677 BENCHMARK(LargeMap) { |
(...skipping 13 matching lines...) Expand all Loading... |
712 uint8_t* buffer; | 691 uint8_t* buffer; |
713 Timer timer(true, "Large Map"); | 692 Timer timer(true, "Large Map"); |
714 timer.Start(); | 693 timer.Start(); |
715 for (intptr_t i = 0; i < kLoopCount; i++) { | 694 for (intptr_t i = 0; i < kLoopCount; i++) { |
716 StackZone zone(thread); | 695 StackZone zone(thread); |
717 MessageWriter writer(&buffer, &malloc_allocator, true); | 696 MessageWriter writer(&buffer, &malloc_allocator, true); |
718 writer.WriteMessage(map); | 697 writer.WriteMessage(map); |
719 intptr_t buffer_len = writer.BytesWritten(); | 698 intptr_t buffer_len = writer.BytesWritten(); |
720 | 699 |
721 // Read object back from the snapshot. | 700 // Read object back from the snapshot. |
722 MessageSnapshotReader reader(buffer, | 701 MessageSnapshotReader reader(buffer, buffer_len, thread); |
723 buffer_len, | |
724 thread); | |
725 reader.ReadObject(); | 702 reader.ReadObject(); |
726 free(buffer); | 703 free(buffer); |
727 } | 704 } |
728 timer.Stop(); | 705 timer.Stop(); |
729 int64_t elapsed_time = timer.TotalElapsedTime(); | 706 int64_t elapsed_time = timer.TotalElapsedTime(); |
730 benchmark->set_score(elapsed_time); | 707 benchmark->set_score(elapsed_time); |
731 } | 708 } |
732 | 709 |
733 | 710 |
734 BENCHMARK_MEMORY(InitialRSS) { | 711 BENCHMARK_MEMORY(InitialRSS) { |
735 benchmark->set_score(OS::MaxRSS()); | 712 benchmark->set_score(OS::MaxRSS()); |
736 } | 713 } |
737 | 714 |
738 } // namespace dart | 715 } // namespace dart |
OLD | NEW |