| 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 timer.Start(); | 495 timer.Start(); |
| 496 for (intptr_t i = 0; i < kLoopCount; i++) { | 496 for (intptr_t i = 0; i < kLoopCount; i++) { |
| 497 Dart_ExitIsolate(); | 497 Dart_ExitIsolate(); |
| 498 Dart_EnterIsolate(isolate); | 498 Dart_EnterIsolate(isolate); |
| 499 } | 499 } |
| 500 timer.Stop(); | 500 timer.Stop(); |
| 501 int64_t elapsed_time = timer.TotalElapsedTime(); | 501 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 502 benchmark->set_score(elapsed_time); | 502 benchmark->set_score(elapsed_time); |
| 503 } | 503 } |
| 504 | 504 |
| 505 |
| 506 static uint8_t message_buffer[64]; |
| 507 static uint8_t* message_allocator( |
| 508 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 509 return message_buffer; |
| 510 } |
| 511 |
| 512 |
| 513 BENCHMARK(SerializeNull) { |
| 514 const Object& null_object = Object::Handle(); |
| 515 const intptr_t kLoopCount = 1000000; |
| 516 Isolate* isolate = Isolate::Current(); |
| 517 uint8_t* buffer; |
| 518 Timer timer(true, "Serialize Null"); |
| 519 timer.Start(); |
| 520 for (intptr_t i = 0; i < kLoopCount; i++) { |
| 521 MessageWriter writer(&buffer, &message_allocator); |
| 522 writer.WriteMessage(null_object); |
| 523 intptr_t buffer_len = writer.BytesWritten(); |
| 524 |
| 525 // Read object back from the snapshot. |
| 526 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); |
| 527 reader.ReadObject(); |
| 528 } |
| 529 timer.Stop(); |
| 530 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 531 benchmark->set_score(elapsed_time); |
| 532 } |
| 533 |
| 534 |
| 535 BENCHMARK(SerializeSmi) { |
| 536 const Integer& smi_object = Integer::Handle(Smi::New(42)); |
| 537 const intptr_t kLoopCount = 1000000; |
| 538 Isolate* isolate = Isolate::Current(); |
| 539 uint8_t* buffer; |
| 540 Timer timer(true, "Serialize Smi"); |
| 541 timer.Start(); |
| 542 for (intptr_t i = 0; i < kLoopCount; i++) { |
| 543 MessageWriter writer(&buffer, &message_allocator); |
| 544 writer.WriteMessage(smi_object); |
| 545 intptr_t buffer_len = writer.BytesWritten(); |
| 546 |
| 547 // Read object back from the snapshot. |
| 548 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); |
| 549 reader.ReadObject(); |
| 550 } |
| 551 timer.Stop(); |
| 552 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 553 benchmark->set_score(elapsed_time); |
| 554 } |
| 555 |
| 556 |
| 557 BENCHMARK(SimpleMessage) { |
| 558 const Array& array_object = Array::Handle(Array::New(2)); |
| 559 array_object.SetAt(0, Integer::Handle(Smi::New(42))); |
| 560 array_object.SetAt(1, Object::Handle()); |
| 561 const intptr_t kLoopCount = 1000000; |
| 562 Isolate* isolate = Isolate::Current(); |
| 563 uint8_t* buffer; |
| 564 Timer timer(true, "Simple Message"); |
| 565 timer.Start(); |
| 566 for (intptr_t i = 0; i < kLoopCount; i++) { |
| 567 MessageWriter writer(&buffer, &malloc_allocator); |
| 568 writer.WriteMessage(array_object); |
| 569 intptr_t buffer_len = writer.BytesWritten(); |
| 570 |
| 571 // Read object back from the snapshot. |
| 572 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); |
| 573 reader.ReadObject(); |
| 574 free(buffer); |
| 575 } |
| 576 timer.Stop(); |
| 577 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 578 benchmark->set_score(elapsed_time); |
| 579 } |
| 580 |
| 505 } // namespace dart | 581 } // namespace dart |
| OLD | NEW |