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

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

Issue 10897014: Performance improvement for the Dart VM runtime method (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | runtime/vm/dart_api_impl.cc » ('J')
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/file.h" 7 #include "bin/file.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 Dart_NewString("benchmark"), 193 Dart_NewString("benchmark"),
194 1, 194 1,
195 args); 195 args);
196 timer.Stop(); 196 timer.Stop();
197 int64_t elapsed_time = timer.TotalElapsedTime(); 197 int64_t elapsed_time = timer.TotalElapsedTime();
198 benchmark->set_score(elapsed_time); 198 benchmark->set_score(elapsed_time);
199 } 199 }
200 200
201 201
202 // 202 //
203 // Measure time accessing internal and external strings.
204 //
205 static void DartStringAccess(Dart_NativeArguments args) {
206 Dart_EnterScope();
207 int count = Dart_GetNativeArgumentCount(args);
208 EXPECT_EQ(2, count);
209
210 // Get interations parameter.
211 Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
212 EXPECT_VALID(param1);
213 EXPECT(Dart_IsInteger(param1));
214 bool fits = false;
215 Dart_Handle result = Dart_IntegerFitsIntoInt64(param1, &fits);
216 EXPECT_VALID(result);
217 EXPECT(fits);
218 int64_t iterations;
219 result = Dart_IntegerToInt64(param1, &iterations);
220 EXPECT_VALID(result);
221 EXPECT_LE(0, iterations);
222 EXPECT_LE(iterations, 10000000);
223
224 // Create strings.
225 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
226 int external_peer_data = 123;
227 Dart_Handle external_string = Dart_NewExternalString8(data8,
228 ARRAY_SIZE(data8),
229 &external_peer_data,
230 NULL);
231 Dart_Handle internal_string = Dart_NewString("two");
232
233 // Run benchmark.
234 for (int64_t i = 0; i < iterations; i++) {
Ivan Posva 2012/08/28 22:21:20 Since this is essentially the benchmark you can dr
235 EXPECT(Dart_IsString(internal_string));
236 EXPECT(Dart_IsString8(internal_string));
237 EXPECT(Dart_IsString16(internal_string));
238 EXPECT(!Dart_IsExternalString(internal_string));
239 EXPECT_VALID(external_string);
240 EXPECT(Dart_IsExternalString(external_string));
241 void* external_peer = NULL;
242 // 80% of benchmark is spent in the following call.
243 EXPECT_VALID(Dart_ExternalStringGetPeer(external_string, &external_peer));
244 EXPECT_EQ(&external_peer_data, external_peer);
245 }
246
247 Dart_ExitScope();
248 }
249
250
251 static Dart_NativeFunction bm_dsa_lookup(Dart_Handle name, int argument_count) {
252 const char* cstr = NULL;
253 Dart_Handle result = Dart_StringToCString(name, &cstr);
254 EXPECT_VALID(result);
255 if (strcmp(cstr, "init") == 0) {
256 return InitNativeFields;
257 } else {
258 return DartStringAccess;
259 }
260 }
261
262
263 BENCHMARK(DartStringAccess) {
264 const int kNumIterations = 10000000;
265 const char* kScriptChars =
266 "class Class extends NativeFieldsWrapper{\n"
267 " int init() native 'init';\n"
268 " int method(int param1) native 'method';\n"
269 "}\n"
270 "\n"
271 "void benchmark(int count) {\n"
272 " Class c = new Class();\n"
273 " c.method(count);\n"
274 "}\n";
275
276 Dart_Handle lib = TestCase::LoadTestScript(
277 kScriptChars,
278 reinterpret_cast<Dart_NativeEntryResolver>(bm_dsa_lookup));
279
280 // Create a native wrapper class with native fields.
281 Dart_Handle result = Dart_CreateNativeWrapperClass(
282 lib,
283 Dart_NewString("NativeFieldsWrapper"),
284 1);
285 EXPECT_VALID(result);
286
287 Dart_Handle args[1];
288 args[0] = Dart_NewInteger(kNumIterations);
289
290 // Warmup first to avoid compilation jitters.
291 result = Dart_Invoke(lib,
292 Dart_NewString("benchmark"),
293 1,
294 args);
295 EXPECT_VALID(result);
296
297 Timer timer(true, "DartStringAccess benchmark");
298 timer.Start();
299 Dart_Invoke(lib,
300 Dart_NewString("benchmark"),
301 1,
302 args);
303 timer.Stop();
304 int64_t elapsed_time = timer.TotalElapsedTime();
305 benchmark->set_score(elapsed_time);
306 }
307
308
309 //
203 // Measure compile of all dart2js(compiler) functions. 310 // Measure compile of all dart2js(compiler) functions.
204 // 311 //
205 static char* ComputeDart2JSPath(const char* arg) { 312 static char* ComputeDart2JSPath(const char* arg) {
206 char buffer[2048]; 313 char buffer[2048];
207 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); 314 char* dart2js_path = strdup(File::GetCanonicalPath(arg));
208 const char* compiler_path = "%s%slib%scompiler%scompiler.dart"; 315 const char* compiler_path = "%s%slib%scompiler%scompiler.dart";
209 const char* path_separator = File::PathSeparator(); 316 const char* path_separator = File::PathSeparator();
210 ASSERT(path_separator != NULL && strlen(path_separator) == 1); 317 ASSERT(path_separator != NULL && strlen(path_separator) == 1);
211 char* ptr = strrchr(dart2js_path, *path_separator); 318 char* ptr = strrchr(dart2js_path, *path_separator);
212 while (ptr != NULL) { 319 while (ptr != NULL) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); 456 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest"));
350 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); 457 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
351 EXPECT_VALID(result); 458 EXPECT_VALID(result);
352 int64_t elapsed_time = 0; 459 int64_t elapsed_time = 0;
353 result = Dart_IntegerToInt64(result, &elapsed_time); 460 result = Dart_IntegerToInt64(result, &elapsed_time);
354 EXPECT_VALID(result); 461 EXPECT_VALID(result);
355 benchmark->set_score(elapsed_time); 462 benchmark->set_score(elapsed_time);
356 } 463 }
357 464
358 } // namespace dart 465 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | runtime/vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698