| 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" |
| 6 |
| 7 #include "bin/file.h" |
| 8 |
| 5 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 6 | 10 |
| 7 #include "vm/benchmark_test.h" | |
| 8 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 9 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
| 10 #include "vm/unit_test.h" | 13 #include "vm/unit_test.h" |
| 11 | 14 |
| 12 namespace dart { | 15 namespace dart { |
| 13 | 16 |
| 14 Benchmark* Benchmark::first_ = NULL; | 17 Benchmark* Benchmark::first_ = NULL; |
| 15 Benchmark* Benchmark::tail_ = NULL; | 18 Benchmark* Benchmark::tail_ = NULL; |
| 19 const char* Benchmark::executable_ = NULL; |
| 16 | 20 |
| 17 void Benchmark::RunAll() { | 21 void Benchmark::RunAll(const char* executable) { |
| 22 SetExecutable(executable); |
| 18 Benchmark* benchmark = first_; | 23 Benchmark* benchmark = first_; |
| 19 while (benchmark != NULL) { | 24 while (benchmark != NULL) { |
| 20 benchmark->RunBenchmark(); | 25 benchmark->RunBenchmark(); |
| 21 benchmark = benchmark->next_; | 26 benchmark = benchmark->next_; |
| 22 } | 27 } |
| 23 } | 28 } |
| 24 | 29 |
| 25 | 30 |
| 26 // Compiler only implemented on IA32 and X64 now. | 31 // Compiler only implemented on IA32 and X64 now. |
| 27 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 32 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Dart_Invoke(lib, | 179 Dart_Invoke(lib, |
| 175 Dart_NewString("benchmark"), | 180 Dart_NewString("benchmark"), |
| 176 1, | 181 1, |
| 177 args); | 182 args); |
| 178 timer.Stop(); | 183 timer.Stop(); |
| 179 int64_t elapsed_time = timer.TotalElapsedTime(); | 184 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 180 benchmark->set_score(elapsed_time); | 185 benchmark->set_score(elapsed_time); |
| 181 } | 186 } |
| 182 | 187 |
| 183 | 188 |
| 184 #if 0 | |
| 185 // | 189 // |
| 186 // Measure compile of all dart2js(compiler) functions. | 190 // Measure compile of all dart2js(compiler) functions. |
| 187 // | 191 // |
| 192 static char* ComputeDart2JSPath(const char* arg) { |
| 193 char buffer[2048]; |
| 194 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); |
| 195 const char* compiler_path = "%s%slib%scompiler%scompiler.dart"; |
| 196 const char* path_separator = File::PathSeparator(); |
| 197 ASSERT(path_separator != NULL && strlen(path_separator) == 1); |
| 198 char* ptr = strrchr(dart2js_path, *path_separator); |
| 199 while (ptr != NULL) { |
| 200 *ptr = '\0'; |
| 201 OS::SNPrint(buffer, 2048, compiler_path, |
| 202 dart2js_path, |
| 203 path_separator, |
| 204 path_separator, |
| 205 path_separator); |
| 206 if (File::Exists(buffer)) { |
| 207 break; |
| 208 } |
| 209 ptr = strrchr(dart2js_path, *path_separator); |
| 210 } |
| 211 if (ptr == NULL) { |
| 212 free(dart2js_path); |
| 213 dart2js_path = NULL; |
| 214 } |
| 215 return dart2js_path; |
| 216 } |
| 217 |
| 218 |
| 188 static void func(Dart_NativeArguments args) { | 219 static void func(Dart_NativeArguments args) { |
| 189 } | 220 } |
| 190 | 221 |
| 191 | 222 |
| 192 static Dart_NativeFunction NativeResolver(Dart_Handle name, | 223 static Dart_NativeFunction NativeResolver(Dart_Handle name, |
| 193 int arg_count) { | 224 int arg_count) { |
| 194 return &func; | 225 return &func; |
| 195 } | 226 } |
| 196 | 227 |
| 197 | 228 |
| 198 BENCHMARK(Dart2JSCompileAll) { | 229 BENCHMARK(Dart2JSCompileAll) { |
| 199 const char* kScriptChars = "#import('lib/compiler/compiler.dart');"; | 230 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
| 231 Dart_Handle import_map; |
| 232 if (dart_root != NULL) { |
| 233 import_map = Dart_NewList(2); |
| 234 Dart_ListSetAt(import_map, 0, Dart_NewString("DART_ROOT")); |
| 235 Dart_ListSetAt(import_map, 1, Dart_NewString(dart_root)); |
| 236 } else { |
| 237 import_map = Dart_NewList(0); |
| 238 } |
| 239 const char* kScriptChars = |
| 240 "#import('${DART_ROOT}/lib/compiler/compiler.dart');"; |
| 200 Dart_Handle lib = TestCase::LoadTestScript( | 241 Dart_Handle lib = TestCase::LoadTestScript( |
| 201 kScriptChars, | 242 kScriptChars, |
| 202 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | 243 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver), |
| 244 import_map); |
| 203 EXPECT(!Dart_IsError(lib)); | 245 EXPECT(!Dart_IsError(lib)); |
| 204 Timer timer(true, "Compile all of dart2js benchmark"); | 246 Timer timer(true, "Compile all of dart2js benchmark"); |
| 205 timer.Start(); | 247 timer.Start(); |
| 206 Dart_Handle result = Dart_CompileAll(); | 248 Dart_Handle result = Dart_CompileAll(); |
| 207 EXPECT(!Dart_IsError(result)); | 249 EXPECT(!Dart_IsError(result)); |
| 208 timer.Stop(); | 250 timer.Stop(); |
| 209 int64_t elapsed_time = timer.TotalElapsedTime(); | 251 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 210 benchmark->set_score(elapsed_time); | 252 benchmark->set_score(elapsed_time); |
| 253 free(dart_root); |
| 211 } | 254 } |
| 212 #endif | |
| 213 | 255 |
| 214 | 256 |
| 215 // | 257 // |
| 216 // Measure frame lookup during stack traversal. | 258 // Measure frame lookup during stack traversal. |
| 217 // | 259 // |
| 218 static void StackFrame_accessFrame(Dart_NativeArguments args) { | 260 static void StackFrame_accessFrame(Dart_NativeArguments args) { |
| 219 const int kNumIterations = 100; | 261 const int kNumIterations = 100; |
| 220 Dart_EnterScope(); | 262 Dart_EnterScope(); |
| 221 Code& code = Code::Handle(); | 263 Code& code = Code::Handle(); |
| 222 Timer timer(true, "LookupDartCode benchmark"); | 264 Timer timer(true, "LookupDartCode benchmark"); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); | 335 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); |
| 294 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); | 336 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("StackFrameTest")); |
| 295 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 337 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); |
| 296 EXPECT_VALID(result); | 338 EXPECT_VALID(result); |
| 297 int64_t elapsed_time = 0; | 339 int64_t elapsed_time = 0; |
| 298 EXPECT(!Dart_IsError(Dart_IntegerToInt64(result, &elapsed_time))); | 340 EXPECT(!Dart_IsError(Dart_IntegerToInt64(result, &elapsed_time))); |
| 299 benchmark->set_score(elapsed_time); | 341 benchmark->set_score(elapsed_time); |
| 300 } | 342 } |
| 301 | 343 |
| 302 } // namespace dart | 344 } // namespace dart |
| OLD | NEW |