| 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/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 Loading... |
| 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 BENCHMARK(DartStringAccess) { |
| 206 const int kNumIterations = 10000000; |
| 207 Timer timer(true, "DartStringAccess benchmark"); |
| 208 timer.Start(); |
| 209 Dart_EnterScope(); |
| 210 |
| 211 // Create strings. |
| 212 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; |
| 213 int external_peer_data = 123; |
| 214 Dart_Handle external_string = Dart_NewExternalString8(data8, |
| 215 ARRAY_SIZE(data8), |
| 216 &external_peer_data, |
| 217 NULL); |
| 218 Dart_Handle internal_string = Dart_NewString("two"); |
| 219 |
| 220 // Run benchmark. |
| 221 for (int64_t i = 0; i < kNumIterations; i++) { |
| 222 EXPECT(Dart_IsString(internal_string)); |
| 223 EXPECT(Dart_IsString8(internal_string)); |
| 224 EXPECT(Dart_IsString16(internal_string)); |
| 225 EXPECT(!Dart_IsExternalString(internal_string)); |
| 226 EXPECT_VALID(external_string); |
| 227 EXPECT(Dart_IsExternalString(external_string)); |
| 228 void* external_peer = NULL; |
| 229 EXPECT_VALID(Dart_ExternalStringGetPeer(external_string, &external_peer)); |
| 230 EXPECT_EQ(&external_peer_data, external_peer); |
| 231 } |
| 232 |
| 233 Dart_ExitScope(); |
| 234 timer.Stop(); |
| 235 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 236 benchmark->set_score(elapsed_time); |
| 237 } |
| 238 |
| 239 |
| 240 // |
| 203 // Measure compile of all dart2js(compiler) functions. | 241 // Measure compile of all dart2js(compiler) functions. |
| 204 // | 242 // |
| 205 static char* ComputeDart2JSPath(const char* arg) { | 243 static char* ComputeDart2JSPath(const char* arg) { |
| 206 char buffer[2048]; | 244 char buffer[2048]; |
| 207 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); | 245 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); |
| 208 const char* compiler_path = "%s%slib%scompiler%scompiler.dart"; | 246 const char* compiler_path = "%s%slib%scompiler%scompiler.dart"; |
| 209 const char* path_separator = File::PathSeparator(); | 247 const char* path_separator = File::PathSeparator(); |
| 210 ASSERT(path_separator != NULL && strlen(path_separator) == 1); | 248 ASSERT(path_separator != NULL && strlen(path_separator) == 1); |
| 211 char* ptr = strrchr(dart2js_path, *path_separator); | 249 char* ptr = strrchr(dart2js_path, *path_separator); |
| 212 while (ptr != NULL) { | 250 while (ptr != NULL) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); | 387 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); |
| 350 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 388 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); |
| 351 EXPECT_VALID(result); | 389 EXPECT_VALID(result); |
| 352 int64_t elapsed_time = 0; | 390 int64_t elapsed_time = 0; |
| 353 result = Dart_IntegerToInt64(result, &elapsed_time); | 391 result = Dart_IntegerToInt64(result, &elapsed_time); |
| 354 EXPECT_VALID(result); | 392 EXPECT_VALID(result); |
| 355 benchmark->set_score(elapsed_time); | 393 benchmark->set_score(elapsed_time); |
| 356 } | 394 } |
| 357 | 395 |
| 358 } // namespace dart | 396 } // namespace dart |
| OLD | NEW |