Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: runtime/vm/benchmark_test.cc

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/benchmark_test.h ('k') | runtime/vm/bit_vector_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 DART_CHECK_VALID(result); 346 DART_CHECK_VALID(result);
347 } 347 }
348 348
349 BENCHMARK(Dart2JSCompileAll) { 349 BENCHMARK(Dart2JSCompileAll) {
350 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); 350 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
351 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); 351 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary);
352 SetupDart2JSPackagePath(); 352 SetupDart2JSPackagePath();
353 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); 353 char* dart_root = ComputeDart2JSPath(Benchmark::Executable());
354 char* script = NULL; 354 char* script = NULL;
355 if (dart_root != NULL) { 355 if (dart_root != NULL) {
356 Isolate* isolate = Isolate::Current(); 356 HANDLESCOPE(thread);
357 HANDLESCOPE(isolate);
358 const char* kFormatStr = 357 const char* kFormatStr =
359 "import '%s/pkg/compiler/lib/compiler.dart';"; 358 "import '%s/pkg/compiler/lib/compiler.dart';";
360 intptr_t len = OS::SNPrint(NULL, 0, kFormatStr, dart_root) + 1; 359 intptr_t len = OS::SNPrint(NULL, 0, kFormatStr, dart_root) + 1;
361 script = reinterpret_cast<char*>(malloc(len)); 360 script = reinterpret_cast<char*>(malloc(len));
362 EXPECT(script != NULL); 361 EXPECT(script != NULL);
363 OS::SNPrint(script, len, kFormatStr, dart_root); 362 OS::SNPrint(script, len, kFormatStr, dart_root);
364 Dart_Handle lib = TestCase::LoadTestScript( 363 Dart_Handle lib = TestCase::LoadTestScript(
365 script, 364 script,
366 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); 365 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver));
367 EXPECT_VALID(lib); 366 EXPECT_VALID(lib);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 static uint8_t message_buffer[64]; 587 static uint8_t message_buffer[64];
589 static uint8_t* message_allocator( 588 static uint8_t* message_allocator(
590 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 589 uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
591 return message_buffer; 590 return message_buffer;
592 } 591 }
593 592
594 593
595 BENCHMARK(SerializeNull) { 594 BENCHMARK(SerializeNull) {
596 const Object& null_object = Object::Handle(); 595 const Object& null_object = Object::Handle();
597 const intptr_t kLoopCount = 1000000; 596 const intptr_t kLoopCount = 1000000;
598 Isolate* isolate = Isolate::Current(); 597 Isolate* isolate = thread->isolate();
599 uint8_t* buffer; 598 uint8_t* buffer;
600 Timer timer(true, "Serialize Null"); 599 Timer timer(true, "Serialize Null");
601 timer.Start(); 600 timer.Start();
602 for (intptr_t i = 0; i < kLoopCount; i++) { 601 for (intptr_t i = 0; i < kLoopCount; i++) {
603 StackZone zone(isolate); 602 StackZone zone(isolate);
604 MessageWriter writer(&buffer, &message_allocator, true); 603 MessageWriter writer(&buffer, &message_allocator, true);
605 writer.WriteMessage(null_object); 604 writer.WriteMessage(null_object);
606 intptr_t buffer_len = writer.BytesWritten(); 605 intptr_t buffer_len = writer.BytesWritten();
607 606
608 // Read object back from the snapshot. 607 // Read object back from the snapshot.
609 MessageSnapshotReader reader(buffer, 608 MessageSnapshotReader reader(buffer,
610 buffer_len, 609 buffer_len,
611 isolate, 610 thread);
612 zone.GetZone());
613 reader.ReadObject(); 611 reader.ReadObject();
614 } 612 }
615 timer.Stop(); 613 timer.Stop();
616 int64_t elapsed_time = timer.TotalElapsedTime(); 614 int64_t elapsed_time = timer.TotalElapsedTime();
617 benchmark->set_score(elapsed_time); 615 benchmark->set_score(elapsed_time);
618 } 616 }
619 617
620 618
621 BENCHMARK(SerializeSmi) { 619 BENCHMARK(SerializeSmi) {
622 const Integer& smi_object = Integer::Handle(Smi::New(42)); 620 const Integer& smi_object = Integer::Handle(Smi::New(42));
623 const intptr_t kLoopCount = 1000000; 621 const intptr_t kLoopCount = 1000000;
624 Isolate* isolate = Isolate::Current(); 622 Isolate* isolate = thread->isolate();
625 uint8_t* buffer; 623 uint8_t* buffer;
626 Timer timer(true, "Serialize Smi"); 624 Timer timer(true, "Serialize Smi");
627 timer.Start(); 625 timer.Start();
628 for (intptr_t i = 0; i < kLoopCount; i++) { 626 for (intptr_t i = 0; i < kLoopCount; i++) {
629 StackZone zone(isolate); 627 StackZone zone(isolate);
630 MessageWriter writer(&buffer, &message_allocator, true); 628 MessageWriter writer(&buffer, &message_allocator, true);
631 writer.WriteMessage(smi_object); 629 writer.WriteMessage(smi_object);
632 intptr_t buffer_len = writer.BytesWritten(); 630 intptr_t buffer_len = writer.BytesWritten();
633 631
634 // Read object back from the snapshot. 632 // Read object back from the snapshot.
635 MessageSnapshotReader reader(buffer, 633 MessageSnapshotReader reader(buffer,
636 buffer_len, 634 buffer_len,
637 isolate, 635 thread);
638 zone.GetZone());
639 reader.ReadObject(); 636 reader.ReadObject();
640 } 637 }
641 timer.Stop(); 638 timer.Stop();
642 int64_t elapsed_time = timer.TotalElapsedTime(); 639 int64_t elapsed_time = timer.TotalElapsedTime();
643 benchmark->set_score(elapsed_time); 640 benchmark->set_score(elapsed_time);
644 } 641 }
645 642
646 643
647 BENCHMARK(SimpleMessage) { 644 BENCHMARK(SimpleMessage) {
648 const Array& array_object = Array::Handle(Array::New(2)); 645 const Array& array_object = Array::Handle(Array::New(2));
649 array_object.SetAt(0, Integer::Handle(Smi::New(42))); 646 array_object.SetAt(0, Integer::Handle(Smi::New(42)));
650 array_object.SetAt(1, Object::Handle()); 647 array_object.SetAt(1, Object::Handle());
651 const intptr_t kLoopCount = 1000000; 648 const intptr_t kLoopCount = 1000000;
652 Isolate* isolate = Isolate::Current(); 649 Isolate* isolate = thread->isolate();
653 uint8_t* buffer; 650 uint8_t* buffer;
654 Timer timer(true, "Simple Message"); 651 Timer timer(true, "Simple Message");
655 timer.Start(); 652 timer.Start();
656 for (intptr_t i = 0; i < kLoopCount; i++) { 653 for (intptr_t i = 0; i < kLoopCount; i++) {
657 StackZone zone(isolate); 654 StackZone zone(isolate);
658 MessageWriter writer(&buffer, &malloc_allocator, true); 655 MessageWriter writer(&buffer, &malloc_allocator, true);
659 writer.WriteMessage(array_object); 656 writer.WriteMessage(array_object);
660 intptr_t buffer_len = writer.BytesWritten(); 657 intptr_t buffer_len = writer.BytesWritten();
661 658
662 // Read object back from the snapshot. 659 // Read object back from the snapshot.
663 MessageSnapshotReader reader(buffer, 660 MessageSnapshotReader reader(buffer,
664 buffer_len, 661 buffer_len,
665 isolate, 662 thread);
666 zone.GetZone());
667 reader.ReadObject(); 663 reader.ReadObject();
668 free(buffer); 664 free(buffer);
669 } 665 }
670 timer.Stop(); 666 timer.Stop();
671 int64_t elapsed_time = timer.TotalElapsedTime(); 667 int64_t elapsed_time = timer.TotalElapsedTime();
672 benchmark->set_score(elapsed_time); 668 benchmark->set_score(elapsed_time);
673 } 669 }
674 670
675 671
676 BENCHMARK(LargeMap) { 672 BENCHMARK(LargeMap) {
677 const char* kScript = 673 const char* kScript =
678 "makeMap() {\n" 674 "makeMap() {\n"
679 " Map m = {};\n" 675 " Map m = {};\n"
680 " for (int i = 0; i < 100000; ++i) m[i*13+i*(i>>7)] = i;\n" 676 " for (int i = 0; i < 100000; ++i) m[i*13+i*(i>>7)] = i;\n"
681 " return m;\n" 677 " return m;\n"
682 "}"; 678 "}";
679 Isolate* isolate = thread->isolate();
683 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 680 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
684 EXPECT_VALID(h_lib); 681 EXPECT_VALID(h_lib);
685 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); 682 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL);
686 EXPECT_VALID(h_result); 683 EXPECT_VALID(h_result);
687 Instance& map = Instance::Handle(); 684 Instance& map = Instance::Handle();
688 map ^= Api::UnwrapHandle(h_result); 685 map ^= Api::UnwrapHandle(h_result);
689 const intptr_t kLoopCount = 100; 686 const intptr_t kLoopCount = 100;
690 Isolate* isolate = Isolate::Current();
691 uint8_t* buffer; 687 uint8_t* buffer;
692 Timer timer(true, "Large Map"); 688 Timer timer(true, "Large Map");
693 timer.Start(); 689 timer.Start();
694 for (intptr_t i = 0; i < kLoopCount; i++) { 690 for (intptr_t i = 0; i < kLoopCount; i++) {
695 StackZone zone(isolate); 691 StackZone zone(isolate);
696 MessageWriter writer(&buffer, &malloc_allocator, true); 692 MessageWriter writer(&buffer, &malloc_allocator, true);
697 writer.WriteMessage(map); 693 writer.WriteMessage(map);
698 intptr_t buffer_len = writer.BytesWritten(); 694 intptr_t buffer_len = writer.BytesWritten();
699 695
700 // Read object back from the snapshot. 696 // Read object back from the snapshot.
701 MessageSnapshotReader reader(buffer, 697 MessageSnapshotReader reader(buffer,
702 buffer_len, 698 buffer_len,
703 isolate, 699 thread);
704 zone.GetZone());
705 reader.ReadObject(); 700 reader.ReadObject();
706 free(buffer); 701 free(buffer);
707 } 702 }
708 timer.Stop(); 703 timer.Stop();
709 int64_t elapsed_time = timer.TotalElapsedTime(); 704 int64_t elapsed_time = timer.TotalElapsedTime();
710 benchmark->set_score(elapsed_time); 705 benchmark->set_score(elapsed_time);
711 } 706 }
712 707
713 } // namespace dart 708 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/benchmark_test.h ('k') | runtime/vm/bit_vector_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698