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 imp | |
6 import os | |
7 import sys | |
8 import subprocess | |
9 import timeit | |
10 | |
11 try: | |
12 imp.find_module('mopy') | |
13 except ImportError: | |
14 sys.path.append(os.path.abspath(os.path.join( | |
15 __file__, os.pardir, os.pardir, os.pardir, 'mojo', 'tools'))) | |
16 from mopy.paths import Paths | |
17 | |
18 | |
19 def run(args): | |
20 if args.release: | |
21 build_directory = os.path.join('out', 'Release') | |
22 else: | |
23 build_directory = os.path.join('out', 'Debug') | |
24 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.
| |
25 | |
26 rounds = 1000 | |
27 | |
28 # Because mojo_benchmark_startup terminates the process immediately when its | |
29 # MojoMain() is called. The overall execution time reflects the startup | |
30 # performance of the mojo shell. | |
31 startup_time = timeit.timeit( | |
32 ("subprocess.call(['%s', 'mojo:mojo_benchmark_startup'])" % | |
33 paths.mojo_shell_path), | |
34 "import subprocess", number=rounds) | |
35 | |
36 # The execution time of a noop executable is also measured, in order to offset | |
37 # the cost of timeit()/subprocess.call()/etc. | |
38 noop_time = timeit.timeit( | |
39 ("subprocess.call(['%s'])" % | |
40 os.path.join(paths.build_dir, 'mojo_benchmark_startup_noop')), | |
41 "import subprocess", number=rounds) | |
42 | |
43 # TODO(yzshen): Consider also testing the startup time when | |
44 # mojo_benchmark_startup is served by an HTTP server. | |
45 | |
46 # Convert the execution time to milliseconds and compute the average for | |
47 # a single run. | |
48 result = (startup_time - noop_time) * 1000 / rounds | |
49 return ("Result: rounds tested: %d; average startup time: %f ms" % | |
50 (rounds, result)) | |
OLD | NEW |