OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 import subprocess |
| 7 import timeit |
| 8 |
| 9 |
| 10 def run(args, paths): |
| 11 rounds = 1000 |
| 12 |
| 13 # Because mojo_benchmark_startup terminates the process immediately when its |
| 14 # MojoMain() is called. The overall execution time reflects the startup |
| 15 # performance of the mojo shell. |
| 16 startup_time = timeit.timeit( |
| 17 ("subprocess.call(['%s', 'mojo:mojo_benchmark_startup'])" % |
| 18 paths.mojo_shell_path), |
| 19 "import subprocess", number=rounds) |
| 20 |
| 21 # The execution time of a noop executable is also measured, in order to offset |
| 22 # the cost of timeit()/subprocess.call()/etc. |
| 23 noop_time = timeit.timeit( |
| 24 ("subprocess.call(['%s'])" % |
| 25 os.path.join(paths.build_dir, 'mojo_benchmark_startup_noop')), |
| 26 "import subprocess", number=rounds) |
| 27 |
| 28 # TODO(yzshen): Consider also testing the startup time when |
| 29 # mojo_benchmark_startup is served by an HTTP server. |
| 30 |
| 31 # Convert the execution time to milliseconds and compute the average for |
| 32 # a single run. |
| 33 result = (startup_time - noop_time) * 1000 / rounds |
| 34 return ("Result: rounds tested: %d; average startup time: %f ms" % |
| 35 (rounds, result)) |
OLD | NEW |