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

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

Issue 9979016: Add a unit test Benchmark_UseDartApi to measure dart api overhead. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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 | « runtime/vm/dart_api_impl.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 4722 matching lines...) Expand 10 before | Expand all | Expand 10 after
4733 } 4733 }
4734 } 4734 }
4735 4735
4736 // We should have received the expected number of interrupts. 4736 // We should have received the expected number of interrupts.
4737 EXPECT_EQ(kInterruptCount, interrupt_count); 4737 EXPECT_EQ(kInterruptCount, interrupt_count);
4738 4738
4739 // Give the spawned thread enough time to properly exit. 4739 // Give the spawned thread enough time to properly exit.
4740 Isolate::SetInterruptCallback(saved); 4740 Isolate::SetInterruptCallback(saved);
4741 } 4741 }
4742 4742
4743
4744 // The specific api functions called here are a bit arbitrary. We are
4745 // trying to get a sense of the overhead for using the dart api.
4746 void UseDartApi(Dart_NativeArguments args) {
4747 Dart_EnterScope();
4748 int count = Dart_GetNativeArgumentCount(args);
4749 EXPECT_EQ(2, count);
4750
4751 // Get the receiver.
4752 Dart_Handle recv = Dart_GetNativeArgument(args, 0);
4753 EXPECT(!Dart_IsError(recv));
4754
4755 // Get param.
4756 Dart_Handle param = Dart_GetNativeArgument(args, 1);
4757 EXPECT(!Dart_IsError(param));
4758 EXPECT(Dart_IsInteger(param));
4759 bool fits = false;
4760 Dart_Handle result = Dart_IntegerFitsIntoInt64(param, &fits);
4761 EXPECT(!Dart_IsError(result) && fits);
4762 int64_t value1;
4763 result = Dart_IntegerToInt64(param, &value1);
4764 EXPECT(!Dart_IsError(result));
4765
4766 // Get receiver.field.
4767 Dart_Handle field_name = Dart_NewString("field");
Anton Muhin 2012/04/04 18:12:36 this might be a separate issue. and DOM bindings
turnidge 2012/04/04 19:40:22 Changed the benchmark to do native field access, t
4768 Dart_Handle field_value = Dart_GetField(recv, field_name);
4769 EXPECT(!Dart_IsError(field_value));
4770 EXPECT(Dart_IsInteger(field_value));
4771 fits = false;
4772 result = Dart_IntegerFitsIntoInt64(field_value, &fits);
4773 EXPECT(!Dart_IsError(result) && fits);
4774 int64_t value2;
4775 result = Dart_IntegerToInt64(field_value, &value2);
4776 EXPECT(!Dart_IsError(result));
4777 EXPECT_EQ(7, value2);
4778
4779 // Return param + receiver.field.
4780 Dart_SetReturnValue(args, Dart_NewInteger(value1 + value2));
Anton Muhin 2012/04/04 18:12:36 just in case: you may want to assert you always fi
turnidge 2012/04/04 19:40:22 Added some range checks for param, which should ke
4781 Dart_ExitScope();
4782 }
4783
4784
4785 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) {
4786 return reinterpret_cast<Dart_NativeFunction>(&UseDartApi);
4787 }
4788
4789
4790 TEST_CASE(Benchmark_UseDartApi) {
4791 const char* kScriptChars =
4792 "class Class {\n"
4793 " int field = 7;\n"
4794 " int method(int param) native 'Name_Does_Not_Matter';\n"
4795 "}\n"
4796 "\n"
4797 "double benchmark(int count) {\n"
4798 " Class c = new Class();\n"
4799 " Stopwatch sw = new Stopwatch.start();\n"
4800 " for (int i = 0; i < count; i++) {\n"
4801 " c.method(i);\n"
4802 " }\n"
4803 " sw.stop();\n"
4804 " return sw.elapsedInUs() / count;\n"
4805 "}\n";
4806
4807 Dart_Handle lib = TestCase::LoadTestScript(
4808 kScriptChars,
4809 reinterpret_cast<Dart_NativeEntryResolver>(bm_uda_lookup));
4810 Dart_Handle args[1];
4811 args[0] = Dart_NewInteger(10000);
4812 Dart_Handle result = Dart_Invoke(lib,
4813 Dart_NewString("benchmark"),
4814 1,
4815 args);
4816 EXPECT_VALID(result);
4817 EXPECT(Dart_IsDouble(result));
4818 double out;
4819 result = Dart_DoubleValue(result, &out);
4820 fprintf(stderr, "Benchmark_UseDartApi: %f us per iteration\n", out);
4821 }
4822
4743 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4823 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4744 4824
4745 } // namespace dart 4825 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698