Index: benchmarks/startup/run.py |
diff --git a/benchmarks/startup/run.py b/benchmarks/startup/run.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b258e06d0d6ee6106857ab9c94c40398a8fbbf0d |
--- /dev/null |
+++ b/benchmarks/startup/run.py |
@@ -0,0 +1,50 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import imp |
+import os |
+import sys |
+import subprocess |
+import timeit |
+ |
+try: |
+ imp.find_module('mopy') |
+except ImportError: |
+ sys.path.append(os.path.abspath(os.path.join( |
+ __file__, os.pardir, os.pardir, os.pardir, 'mojo', 'tools'))) |
+from mopy.paths import Paths |
+ |
+ |
+def run(args): |
+ if args.release: |
+ build_directory = os.path.join('out', 'Release') |
+ else: |
+ build_directory = os.path.join('out', 'Debug') |
+ paths = Paths(build_directory) |
abarth-chromium
2014/11/14 04:44:13
Why not just pass in |paths| instead of making the
yzshen1
2014/11/14 18:00:15
Done.
|
+ |
+ rounds = 1000 |
+ |
+ # Because mojo_benchmark_startup terminates the process immediately when its |
+ # MojoMain() is called. The overall execution time reflects the startup |
+ # performance of the mojo shell. |
+ startup_time = timeit.timeit( |
+ ("subprocess.call(['%s', 'mojo:mojo_benchmark_startup'])" % |
+ paths.mojo_shell_path), |
+ "import subprocess", number=rounds) |
+ |
+ # The execution time of a noop executable is also measured, in order to offset |
+ # the cost of timeit()/subprocess.call()/etc. |
+ noop_time = timeit.timeit( |
+ ("subprocess.call(['%s'])" % |
+ os.path.join(paths.build_dir, 'mojo_benchmark_startup_noop')), |
+ "import subprocess", number=rounds) |
+ |
+ # TODO(yzshen): Consider also testing the startup time when |
+ # mojo_benchmark_startup is served by an HTTP server. |
+ |
+ # Convert the execution time to milliseconds and compute the average for |
+ # a single run. |
+ result = (startup_time - noop_time) * 1000 / rounds |
+ return ("Result: rounds tested: %d; average startup time: %f ms" % |
+ (rounds, result)) |