| 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 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 "void benchmark(int count) {\n" | 146 "void benchmark(int count) {\n" |
| 147 " Class c = new Class();\n" | 147 " Class c = new Class();\n" |
| 148 " c.init();\n" | 148 " c.init();\n" |
| 149 " for (int i = 0; i < count; i++) {\n" | 149 " for (int i = 0; i < count; i++) {\n" |
| 150 " c.method(i,7);\n" | 150 " c.method(i,7);\n" |
| 151 " }\n" | 151 " }\n" |
| 152 "}\n"; | 152 "}\n"; |
| 153 | 153 |
| 154 Dart_Handle lib = TestCase::LoadTestScript( | 154 Dart_Handle lib = TestCase::LoadTestScript( |
| 155 kScriptChars, | 155 kScriptChars, |
| 156 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup)); | 156 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup), |
| 157 USER_TEST_URI, |
| 158 false); |
| 157 | 159 |
| 158 // Create a native wrapper class with native fields. | 160 // Create a native wrapper class with native fields. |
| 159 Dart_Handle result = Dart_CreateNativeWrapperClass( | 161 Dart_Handle result = Dart_CreateNativeWrapperClass( |
| 160 lib, NewString("NativeFieldsWrapper"), 1); | 162 lib, NewString("NativeFieldsWrapper"), 1); |
| 161 EXPECT_VALID(result); | 163 EXPECT_VALID(result); |
| 164 result = Dart_FinalizeLoading(false); |
| 165 EXPECT_VALID(result); |
| 162 | 166 |
| 163 Dart_Handle args[1]; | 167 Dart_Handle args[1]; |
| 164 args[0] = Dart_NewInteger(kNumIterations); | 168 args[0] = Dart_NewInteger(kNumIterations); |
| 165 | 169 |
| 166 // Warmup first to avoid compilation jitters. | 170 // Warmup first to avoid compilation jitters. |
| 167 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 171 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
| 168 | 172 |
| 169 Timer timer(true, "UseDartApi benchmark"); | 173 Timer timer(true, "UseDartApi benchmark"); |
| 170 timer.Start(); | 174 timer.Start(); |
| 171 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 175 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 "import 'dart:isolate';\n" | 408 "import 'dart:isolate';\n" |
| 405 "import 'dart:mirrors';\n" | 409 "import 'dart:mirrors';\n" |
| 406 "import 'dart:typed_data';\n" | 410 "import 'dart:typed_data';\n" |
| 407 "\n"; | 411 "\n"; |
| 408 | 412 |
| 409 // Start an Isolate, load a script and create a full snapshot. | 413 // Start an Isolate, load a script and create a full snapshot. |
| 410 uint8_t* buffer; | 414 uint8_t* buffer; |
| 411 // Need to load the script into the dart: core library due to | 415 // Need to load the script into the dart: core library due to |
| 412 // the import of dart:_internal. | 416 // the import of dart:_internal. |
| 413 TestCase::LoadCoreTestScript(kScriptChars, NULL); | 417 TestCase::LoadCoreTestScript(kScriptChars, NULL); |
| 414 Api::CheckIsolateState(Isolate::Current()); | 418 Api::CheckAndFinalizePendingClasses(Isolate::Current()); |
| 415 | 419 |
| 416 // Write snapshot with object content. | 420 // Write snapshot with object content. |
| 417 FullSnapshotWriter writer(&buffer, &malloc_allocator); | 421 FullSnapshotWriter writer(&buffer, &malloc_allocator); |
| 418 writer.WriteFullSnapshot(); | 422 writer.WriteFullSnapshot(); |
| 419 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 423 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 420 ASSERT(snapshot->kind() == Snapshot::kFull); | 424 ASSERT(snapshot->kind() == Snapshot::kFull); |
| 421 benchmark->set_score(snapshot->length()); | 425 benchmark->set_score(snapshot->length()); |
| 422 } | 426 } |
| 423 | 427 |
| 424 | 428 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 435 "import 'dart:typed_data';\n" | 439 "import 'dart:typed_data';\n" |
| 436 "import 'dart:_builtin';\n" | 440 "import 'dart:_builtin';\n" |
| 437 "import 'dart:io';\n" | 441 "import 'dart:io';\n" |
| 438 "\n"; | 442 "\n"; |
| 439 | 443 |
| 440 // Start an Isolate, load a script and create a full snapshot. | 444 // Start an Isolate, load a script and create a full snapshot. |
| 441 uint8_t* buffer; | 445 uint8_t* buffer; |
| 442 // Need to load the script into the dart: core library due to | 446 // Need to load the script into the dart: core library due to |
| 443 // the import of dart:_internal. | 447 // the import of dart:_internal. |
| 444 TestCase::LoadCoreTestScript(kScriptChars, NULL); | 448 TestCase::LoadCoreTestScript(kScriptChars, NULL); |
| 445 Api::CheckIsolateState(Isolate::Current()); | 449 Api::CheckAndFinalizePendingClasses(Isolate::Current()); |
| 446 | 450 |
| 447 // Write snapshot with object content. | 451 // Write snapshot with object content. |
| 448 FullSnapshotWriter writer(&buffer, &malloc_allocator); | 452 FullSnapshotWriter writer(&buffer, &malloc_allocator); |
| 449 writer.WriteFullSnapshot(); | 453 writer.WriteFullSnapshot(); |
| 450 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 454 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 451 ASSERT(snapshot->kind() == Snapshot::kFull); | 455 ASSERT(snapshot->kind() == Snapshot::kFull); |
| 452 benchmark->set_score(snapshot->length()); | 456 benchmark->set_score(snapshot->length()); |
| 453 } | 457 } |
| 454 | 458 |
| 455 | 459 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 471 benchmark->set_score(elapsed_time); | 475 benchmark->set_score(elapsed_time); |
| 472 } | 476 } |
| 473 | 477 |
| 474 | 478 |
| 475 BENCHMARK(EnterExitIsolate) { | 479 BENCHMARK(EnterExitIsolate) { |
| 476 const char* kScriptChars = | 480 const char* kScriptChars = |
| 477 "import 'dart:core';\n" | 481 "import 'dart:core';\n" |
| 478 "\n"; | 482 "\n"; |
| 479 const intptr_t kLoopCount = 1000000; | 483 const intptr_t kLoopCount = 1000000; |
| 480 TestCase::LoadTestScript(kScriptChars, NULL); | 484 TestCase::LoadTestScript(kScriptChars, NULL); |
| 481 Api::CheckIsolateState(Isolate::Current()); | 485 Api::CheckAndFinalizePendingClasses(Isolate::Current()); |
| 482 Dart_Isolate isolate = Dart_CurrentIsolate(); | 486 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 483 Timer timer(true, "Enter and Exit isolate"); | 487 Timer timer(true, "Enter and Exit isolate"); |
| 484 timer.Start(); | 488 timer.Start(); |
| 485 for (intptr_t i = 0; i < kLoopCount; i++) { | 489 for (intptr_t i = 0; i < kLoopCount; i++) { |
| 486 Dart_ExitIsolate(); | 490 Dart_ExitIsolate(); |
| 487 Dart_EnterIsolate(isolate); | 491 Dart_EnterIsolate(isolate); |
| 488 } | 492 } |
| 489 timer.Stop(); | 493 timer.Stop(); |
| 490 int64_t elapsed_time = timer.TotalElapsedTime(); | 494 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 491 benchmark->set_score(elapsed_time); | 495 benchmark->set_score(elapsed_time); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); | 565 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); |
| 562 reader.ReadObject(); | 566 reader.ReadObject(); |
| 563 free(buffer); | 567 free(buffer); |
| 564 } | 568 } |
| 565 timer.Stop(); | 569 timer.Stop(); |
| 566 int64_t elapsed_time = timer.TotalElapsedTime(); | 570 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 567 benchmark->set_score(elapsed_time); | 571 benchmark->set_score(elapsed_time); |
| 568 } | 572 } |
| 569 | 573 |
| 570 } // namespace dart | 574 } // namespace dart |
| OLD | NEW |