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

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

Issue 10896018: Rollback of previous commit -- still under review. (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') | 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 "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 22 matching lines...) Expand all
33 33
34 34
35 // 35 //
36 // Measure compile of all functions in dart core lib classes. 36 // Measure compile of all functions in dart core lib classes.
37 // 37 //
38 BENCHMARK(CorelibCompileAll) { 38 BENCHMARK(CorelibCompileAll) {
39 Timer timer(true, "Compile all of Core lib benchmark"); 39 Timer timer(true, "Compile all of Core lib benchmark");
40 timer.Start(); 40 timer.Start();
41 const Error& error = Error::Handle(benchmark->isolate(), 41 const Error& error = Error::Handle(benchmark->isolate(),
42 Library::CompileAll()); 42 Library::CompileAll());
43 if (!error.IsNull()) {
44 OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s",
45 error.ToErrorCString());
46 }
43 EXPECT(error.IsNull()); 47 EXPECT(error.IsNull());
44 timer.Stop(); 48 timer.Stop();
45 int64_t elapsed_time = timer.TotalElapsedTime(); 49 int64_t elapsed_time = timer.TotalElapsedTime();
46 benchmark->set_score(elapsed_time); 50 benchmark->set_score(elapsed_time);
47 } 51 }
48 52
49 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 53 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64
50 54
51 55
52 // 56 //
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 Dart_NewString("benchmark"), 193 Dart_NewString("benchmark"),
190 1, 194 1,
191 args); 195 args);
192 timer.Stop(); 196 timer.Stop();
193 int64_t elapsed_time = timer.TotalElapsedTime(); 197 int64_t elapsed_time = timer.TotalElapsedTime();
194 benchmark->set_score(elapsed_time); 198 benchmark->set_score(elapsed_time);
195 } 199 }
196 200
197 201
198 // 202 //
199 // Measure time accessing internal and external strings.
200 //
201 static void DartStringAccess(Dart_NativeArguments args) {
202 Dart_EnterScope();
203 int count = Dart_GetNativeArgumentCount(args);
204 EXPECT_EQ(2, count);
205
206 // Get interations parameter.
207 Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
208 EXPECT_VALID(param1);
209 EXPECT(Dart_IsInteger(param1));
210 bool fits = false;
211 Dart_Handle result = Dart_IntegerFitsIntoInt64(param1, &fits);
212 EXPECT_VALID(result);
213 EXPECT(fits);
214 int64_t iterations;
215 result = Dart_IntegerToInt64(param1, &iterations);
216 EXPECT_VALID(result);
217 EXPECT_LE(0, iterations);
218 EXPECT_LE(iterations, 10000000);
219
220 // Create strings.
221 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
222 int external_peer_data = 123;
223 Dart_Handle external_string = Dart_NewExternalString8(data8,
224 ARRAY_SIZE(data8),
225 &external_peer_data,
226 NULL);
227 Dart_Handle internal_string = Dart_NewString("two");
228
229 // Run benchmark.
230 for (int64_t i = 0; i < iterations; i++) {
231 EXPECT(Dart_IsString(internal_string));
232 EXPECT(Dart_IsString8(internal_string));
233 EXPECT(Dart_IsString16(internal_string));
234 EXPECT(!Dart_IsExternalString(internal_string));
235 EXPECT_VALID(external_string);
236 EXPECT(Dart_IsExternalString(external_string));
237 void* external_peer = NULL;
238 // 80% of benchmark is spent in the following call.
239 EXPECT_VALID(Dart_ExternalStringGetPeer(external_string, &external_peer));
240 EXPECT_EQ(&external_peer_data, external_peer);
241 }
242
243 Dart_ExitScope();
244 }
245
246
247 static Dart_NativeFunction bm_dsa_lookup(Dart_Handle name, int argument_count) {
248 const char* cstr = NULL;
249 Dart_Handle result = Dart_StringToCString(name, &cstr);
250 EXPECT_VALID(result);
251 if (strcmp(cstr, "init") == 0) {
252 return InitNativeFields;
253 } else {
254 return DartStringAccess;
255 }
256 }
257
258
259 BENCHMARK(DartStringAccess) {
260 const int kNumIterations = 10000000;
261 const char* kScriptChars =
262 "class Class extends NativeFieldsWrapper{\n"
263 " int init() native 'init';\n"
264 " int method(int param1) native 'method';\n"
265 "}\n"
266 "\n"
267 "void benchmark(int count) {\n"
268 " Class c = new Class();\n"
269 " c.method(count);\n"
270 "}\n";
271
272 Dart_Handle lib = TestCase::LoadTestScript(
273 kScriptChars,
274 reinterpret_cast<Dart_NativeEntryResolver>(bm_dsa_lookup));
275
276 // Create a native wrapper class with native fields.
277 Dart_Handle result = Dart_CreateNativeWrapperClass(
278 lib,
279 Dart_NewString("NativeFieldsWrapper"),
280 1);
281 EXPECT_VALID(result);
282
283 Dart_Handle args[1];
284 args[0] = Dart_NewInteger(kNumIterations);
285
286 // Warmup first to avoid compilation jitters.
287 result = Dart_Invoke(lib,
288 Dart_NewString("benchmark"),
289 1,
290 args);
291 EXPECT_VALID(result);
292
293 Timer timer(true, "DartStringAccess benchmark");
294 timer.Start();
295 Dart_Invoke(lib,
296 Dart_NewString("benchmark"),
297 1,
298 args);
299 timer.Stop();
300 int64_t elapsed_time = timer.TotalElapsedTime();
301 benchmark->set_score(elapsed_time);
302 }
303
304
305 //
306 // Measure compile of all dart2js(compiler) functions. 203 // Measure compile of all dart2js(compiler) functions.
307 // 204 //
308 static char* ComputeDart2JSPath(const char* arg) { 205 static char* ComputeDart2JSPath(const char* arg) {
309 char buffer[2048]; 206 char buffer[2048];
310 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); 207 char* dart2js_path = strdup(File::GetCanonicalPath(arg));
311 const char* compiler_path = "%s%slib%scompiler%scompiler.dart"; 208 const char* compiler_path = "%s%slib%scompiler%scompiler.dart";
312 const char* path_separator = File::PathSeparator(); 209 const char* path_separator = File::PathSeparator();
313 ASSERT(path_separator != NULL && strlen(path_separator) == 1); 210 ASSERT(path_separator != NULL && strlen(path_separator) == 1);
314 char* ptr = strrchr(dart2js_path, *path_separator); 211 char* ptr = strrchr(dart2js_path, *path_separator);
315 while (ptr != NULL) { 212 while (ptr != NULL) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); 349 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest"));
453 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); 350 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
454 EXPECT_VALID(result); 351 EXPECT_VALID(result);
455 int64_t elapsed_time = 0; 352 int64_t elapsed_time = 0;
456 result = Dart_IntegerToInt64(result, &elapsed_time); 353 result = Dart_IntegerToInt64(result, &elapsed_time);
457 EXPECT_VALID(result); 354 EXPECT_VALID(result);
458 benchmark->set_score(elapsed_time); 355 benchmark->set_score(elapsed_time);
459 } 356 }
460 357
461 } // namespace dart 358 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698