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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 10186008: Move the dart API benchmark to the VM benchmark infrastructure so that it will get run as part of r… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « vm/benchmark_test.cc ('k') | no next file » | 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 4524 matching lines...) Expand 10 before | Expand all | Expand 10 after
4535 } 4535 }
4536 } 4536 }
4537 4537
4538 // We should have received the expected number of interrupts. 4538 // We should have received the expected number of interrupts.
4539 EXPECT_EQ(kInterruptCount, interrupt_count); 4539 EXPECT_EQ(kInterruptCount, interrupt_count);
4540 4540
4541 // Give the spawned thread enough time to properly exit. 4541 // Give the spawned thread enough time to properly exit.
4542 Isolate::SetInterruptCallback(saved); 4542 Isolate::SetInterruptCallback(saved);
4543 } 4543 }
4544 4544
4545
4546 void InitNativeFields(Dart_NativeArguments args) {
4547 Dart_EnterScope();
4548 int count = Dart_GetNativeArgumentCount(args);
4549 EXPECT_EQ(1, count);
4550
4551 Dart_Handle recv = Dart_GetNativeArgument(args, 0);
4552 EXPECT(!Dart_IsError(recv));
4553 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7);
4554 EXPECT(!Dart_IsError(result));
4555
4556 Dart_ExitScope();
4557 }
4558
4559
4560 // The specific api functions called here are a bit arbitrary. We are
4561 // trying to get a sense of the overhead for using the dart api.
4562 void UseDartApi(Dart_NativeArguments args) {
4563 Dart_EnterScope();
4564 int count = Dart_GetNativeArgumentCount(args);
4565 EXPECT_EQ(3, count);
4566
4567 // Get the receiver.
4568 Dart_Handle recv = Dart_GetNativeArgument(args, 0);
4569 EXPECT(!Dart_IsError(recv));
4570
4571 // Get param1.
4572 Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
4573 EXPECT(!Dart_IsError(param1));
4574 EXPECT(Dart_IsInteger(param1));
4575 bool fits = false;
4576 Dart_Handle result = Dart_IntegerFitsIntoInt64(param1, &fits);
4577 EXPECT(!Dart_IsError(result) && fits);
4578 int64_t value1;
4579 result = Dart_IntegerToInt64(param1, &value1);
4580 EXPECT(!Dart_IsError(result));
4581 EXPECT_LE(0, value1);
4582 EXPECT_LE(value1, 1000000);
4583
4584 // Get native field from receiver.
4585 intptr_t value2;
4586 result = Dart_GetNativeInstanceField(recv, 0, &value2);
4587 EXPECT(!Dart_IsError(result));
4588 EXPECT_EQ(7, value2);
4589
4590 // Return param + receiver.field.
4591 Dart_SetReturnValue(args, Dart_NewInteger(value1 * value2));
4592 Dart_ExitScope();
4593 }
4594
4595
4596 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) {
4597 const char* cstr = NULL;
4598 Dart_Handle result = Dart_StringToCString(name, &cstr);
4599 EXPECT(!Dart_IsError(result));
4600 if (strcmp(cstr, "init") == 0) {
4601 return InitNativeFields;
4602 } else {
4603 return UseDartApi;
4604 }
4605 }
4606
4607
4608 TEST_CASE(Benchmark_UseDartApi) {
4609 const char* kScriptChars =
4610 "class Class extends NativeFieldsWrapper{\n"
4611 " int init() native 'init';\n"
4612 " int method(int param1, int param2) native 'method';\n"
4613 "}\n"
4614 "\n"
4615 "double benchmark(int count) {\n"
4616 " Class c = new Class();\n"
4617 " c.init();\n"
4618 " Stopwatch sw = new Stopwatch.start();\n"
4619 " for (int i = 0; i < count; i++) {\n"
4620 " c.method(i,7);\n"
4621 " }\n"
4622 " sw.stop();\n"
4623 " return sw.elapsedInUs() / count;\n"
4624 "}\n";
4625
4626 Dart_Handle lib = TestCase::LoadTestScript(
4627 kScriptChars,
4628 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup));
4629
4630 // Create a native wrapper class with native fields.
4631 Dart_Handle result = Dart_CreateNativeWrapperClass(
4632 lib,
4633 Dart_NewString("NativeFieldsWrapper"),
4634 1);
4635 EXPECT_VALID(result);
4636
4637 Dart_Handle args[1];
4638 args[0] = Dart_NewInteger(100000);
4639 result = Dart_Invoke(lib,
4640 Dart_NewString("benchmark"),
4641 1,
4642 args);
4643 EXPECT_VALID(result);
4644 EXPECT(Dart_IsDouble(result));
4645 double out;
4646 result = Dart_DoubleValue(result, &out);
4647 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out);
4648 }
4649
4650 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4545 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4651 4546
4652 } // namespace dart 4547 } // namespace dart
OLDNEW
« no previous file with comments | « vm/benchmark_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698