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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 484 } |
485 | 485 |
486 | 486 |
487 static uint8_t* malloc_allocator(uint8_t* ptr, | 487 static uint8_t* malloc_allocator(uint8_t* ptr, |
488 intptr_t old_size, | 488 intptr_t old_size, |
489 intptr_t new_size) { | 489 intptr_t new_size) { |
490 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); | 490 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); |
491 } | 491 } |
492 | 492 |
493 | 493 |
| 494 static void malloc_deallocator(uint8_t* ptr) { |
| 495 free(ptr); |
| 496 } |
| 497 |
| 498 |
494 BENCHMARK_SIZE(CoreSnapshotSize) { | 499 BENCHMARK_SIZE(CoreSnapshotSize) { |
495 const char* kScriptChars = | 500 const char* kScriptChars = |
496 "import 'dart:async';\n" | 501 "import 'dart:async';\n" |
497 "import 'dart:core';\n" | 502 "import 'dart:core';\n" |
498 "import 'dart:collection';\n" | 503 "import 'dart:collection';\n" |
499 "import 'dart:_internal';\n" | 504 "import 'dart:_internal';\n" |
500 "import 'dart:math';\n" | 505 "import 'dart:math';\n" |
501 "import 'dart:isolate';\n" | 506 "import 'dart:isolate';\n" |
502 "import 'dart:mirrors';\n" | 507 "import 'dart:mirrors';\n" |
503 "import 'dart:typed_data';\n" | 508 "import 'dart:typed_data';\n" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 benchmark->set_score(elapsed_time); | 605 benchmark->set_score(elapsed_time); |
601 } | 606 } |
602 | 607 |
603 | 608 |
604 static uint8_t message_buffer[64]; | 609 static uint8_t message_buffer[64]; |
605 static uint8_t* message_allocator(uint8_t* ptr, | 610 static uint8_t* message_allocator(uint8_t* ptr, |
606 intptr_t old_size, | 611 intptr_t old_size, |
607 intptr_t new_size) { | 612 intptr_t new_size) { |
608 return message_buffer; | 613 return message_buffer; |
609 } | 614 } |
| 615 static void message_deallocator(uint8_t* ptr) {} |
610 | 616 |
611 | 617 |
612 BENCHMARK(SerializeNull) { | 618 BENCHMARK(SerializeNull) { |
613 const Object& null_object = Object::Handle(); | 619 const Object& null_object = Object::Handle(); |
614 const intptr_t kLoopCount = 1000000; | 620 const intptr_t kLoopCount = 1000000; |
615 uint8_t* buffer; | 621 uint8_t* buffer; |
616 Timer timer(true, "Serialize Null"); | 622 Timer timer(true, "Serialize Null"); |
617 timer.Start(); | 623 timer.Start(); |
618 for (intptr_t i = 0; i < kLoopCount; i++) { | 624 for (intptr_t i = 0; i < kLoopCount; i++) { |
619 StackZone zone(thread); | 625 StackZone zone(thread); |
620 MessageWriter writer(&buffer, &message_allocator, true); | 626 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, |
| 627 true); |
621 writer.WriteMessage(null_object); | 628 writer.WriteMessage(null_object); |
622 intptr_t buffer_len = writer.BytesWritten(); | 629 intptr_t buffer_len = writer.BytesWritten(); |
623 | 630 |
624 // Read object back from the snapshot. | 631 // Read object back from the snapshot. |
625 MessageSnapshotReader reader(buffer, buffer_len, thread); | 632 MessageSnapshotReader reader(buffer, buffer_len, thread); |
626 reader.ReadObject(); | 633 reader.ReadObject(); |
627 } | 634 } |
628 timer.Stop(); | 635 timer.Stop(); |
629 int64_t elapsed_time = timer.TotalElapsedTime(); | 636 int64_t elapsed_time = timer.TotalElapsedTime(); |
630 benchmark->set_score(elapsed_time); | 637 benchmark->set_score(elapsed_time); |
631 } | 638 } |
632 | 639 |
633 | 640 |
634 BENCHMARK(SerializeSmi) { | 641 BENCHMARK(SerializeSmi) { |
635 const Integer& smi_object = Integer::Handle(Smi::New(42)); | 642 const Integer& smi_object = Integer::Handle(Smi::New(42)); |
636 const intptr_t kLoopCount = 1000000; | 643 const intptr_t kLoopCount = 1000000; |
637 uint8_t* buffer; | 644 uint8_t* buffer; |
638 Timer timer(true, "Serialize Smi"); | 645 Timer timer(true, "Serialize Smi"); |
639 timer.Start(); | 646 timer.Start(); |
640 for (intptr_t i = 0; i < kLoopCount; i++) { | 647 for (intptr_t i = 0; i < kLoopCount; i++) { |
641 StackZone zone(thread); | 648 StackZone zone(thread); |
642 MessageWriter writer(&buffer, &message_allocator, true); | 649 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, |
| 650 true); |
643 writer.WriteMessage(smi_object); | 651 writer.WriteMessage(smi_object); |
644 intptr_t buffer_len = writer.BytesWritten(); | 652 intptr_t buffer_len = writer.BytesWritten(); |
645 | 653 |
646 // Read object back from the snapshot. | 654 // Read object back from the snapshot. |
647 MessageSnapshotReader reader(buffer, buffer_len, thread); | 655 MessageSnapshotReader reader(buffer, buffer_len, thread); |
648 reader.ReadObject(); | 656 reader.ReadObject(); |
649 } | 657 } |
650 timer.Stop(); | 658 timer.Stop(); |
651 int64_t elapsed_time = timer.TotalElapsedTime(); | 659 int64_t elapsed_time = timer.TotalElapsedTime(); |
652 benchmark->set_score(elapsed_time); | 660 benchmark->set_score(elapsed_time); |
653 } | 661 } |
654 | 662 |
655 | 663 |
656 BENCHMARK(SimpleMessage) { | 664 BENCHMARK(SimpleMessage) { |
657 TransitionNativeToVM transition(thread); | 665 TransitionNativeToVM transition(thread); |
658 const Array& array_object = Array::Handle(Array::New(2)); | 666 const Array& array_object = Array::Handle(Array::New(2)); |
659 array_object.SetAt(0, Integer::Handle(Smi::New(42))); | 667 array_object.SetAt(0, Integer::Handle(Smi::New(42))); |
660 array_object.SetAt(1, Object::Handle()); | 668 array_object.SetAt(1, Object::Handle()); |
661 const intptr_t kLoopCount = 1000000; | 669 const intptr_t kLoopCount = 1000000; |
662 uint8_t* buffer; | 670 uint8_t* buffer; |
663 Timer timer(true, "Simple Message"); | 671 Timer timer(true, "Simple Message"); |
664 timer.Start(); | 672 timer.Start(); |
665 for (intptr_t i = 0; i < kLoopCount; i++) { | 673 for (intptr_t i = 0; i < kLoopCount; i++) { |
666 StackZone zone(thread); | 674 StackZone zone(thread); |
667 MessageWriter writer(&buffer, &malloc_allocator, true); | 675 MessageWriter writer(&buffer, &malloc_allocator, &malloc_deallocator, true); |
668 writer.WriteMessage(array_object); | 676 writer.WriteMessage(array_object); |
669 intptr_t buffer_len = writer.BytesWritten(); | 677 intptr_t buffer_len = writer.BytesWritten(); |
670 | 678 |
671 // Read object back from the snapshot. | 679 // Read object back from the snapshot. |
672 MessageSnapshotReader reader(buffer, buffer_len, thread); | 680 MessageSnapshotReader reader(buffer, buffer_len, thread); |
673 reader.ReadObject(); | 681 reader.ReadObject(); |
674 free(buffer); | 682 free(buffer); |
675 } | 683 } |
676 timer.Stop(); | 684 timer.Stop(); |
677 int64_t elapsed_time = timer.TotalElapsedTime(); | 685 int64_t elapsed_time = timer.TotalElapsedTime(); |
(...skipping 13 matching lines...) Expand all Loading... |
691 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); | 699 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); |
692 EXPECT_VALID(h_result); | 700 EXPECT_VALID(h_result); |
693 Instance& map = Instance::Handle(); | 701 Instance& map = Instance::Handle(); |
694 map ^= Api::UnwrapHandle(h_result); | 702 map ^= Api::UnwrapHandle(h_result); |
695 const intptr_t kLoopCount = 100; | 703 const intptr_t kLoopCount = 100; |
696 uint8_t* buffer; | 704 uint8_t* buffer; |
697 Timer timer(true, "Large Map"); | 705 Timer timer(true, "Large Map"); |
698 timer.Start(); | 706 timer.Start(); |
699 for (intptr_t i = 0; i < kLoopCount; i++) { | 707 for (intptr_t i = 0; i < kLoopCount; i++) { |
700 StackZone zone(thread); | 708 StackZone zone(thread); |
701 MessageWriter writer(&buffer, &malloc_allocator, true); | 709 MessageWriter writer(&buffer, &malloc_allocator, &malloc_deallocator, true); |
702 writer.WriteMessage(map); | 710 writer.WriteMessage(map); |
703 intptr_t buffer_len = writer.BytesWritten(); | 711 intptr_t buffer_len = writer.BytesWritten(); |
704 | 712 |
705 // Read object back from the snapshot. | 713 // Read object back from the snapshot. |
706 MessageSnapshotReader reader(buffer, buffer_len, thread); | 714 MessageSnapshotReader reader(buffer, buffer_len, thread); |
707 reader.ReadObject(); | 715 reader.ReadObject(); |
708 free(buffer); | 716 free(buffer); |
709 } | 717 } |
710 timer.Stop(); | 718 timer.Stop(); |
711 int64_t elapsed_time = timer.TotalElapsedTime(); | 719 int64_t elapsed_time = timer.TotalElapsedTime(); |
712 benchmark->set_score(elapsed_time); | 720 benchmark->set_score(elapsed_time); |
713 } | 721 } |
714 | 722 |
715 | 723 |
716 BENCHMARK_MEMORY(InitialRSS) { | 724 BENCHMARK_MEMORY(InitialRSS) { |
717 benchmark->set_score(OS::MaxRSS()); | 725 benchmark->set_score(OS::MaxRSS()); |
718 } | 726 } |
719 | 727 |
720 } // namespace dart | 728 } // namespace dart |
OLD | NEW |