OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 |
5 import os | 6 import os |
6 import sys | 7 import sys |
7 import time | 8 import time |
8 | 9 |
9 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
10 | 11 |
11 from telemetry.core import browser_finder | 12 from telemetry.core import browser_finder |
12 from telemetry.core import browser_options | 13 from telemetry.core import browser_options |
13 | 14 |
| 15 |
14 def Main(args): | 16 def Main(args): |
15 options = browser_options.BrowserFinderOptions() | 17 options = browser_options.BrowserFinderOptions() |
16 parser = options.CreateParser('telemetry_perf_test.py') | 18 parser = options.CreateParser('telemetry_perf_test.py') |
17 options, args = parser.parse_args(args) | 19 options, args = parser.parse_args(args) |
18 | 20 |
19 browser_to_create = browser_finder.FindBrowser(options) | 21 browser_to_create = browser_finder.FindBrowser(options) |
20 assert browser_to_create | 22 assert browser_to_create |
21 with browser_to_create.Create() as b: | 23 with browser_to_create.Create() as b: |
22 tab = b.tabs[0] | 24 tab = b.tabs[0] |
23 | 25 |
24 # Measure round-trip-time for evaluate | 26 # Measure round-trip-time for evaluate |
25 times = [] | 27 times = [] |
26 for i in range(1000): | 28 for i in range(1000): |
27 start = time.time() | 29 start = time.time() |
28 tab.EvaluateJavaScript('%i * 2' % i) | 30 tab.EvaluateJavaScript('%i * 2' % i) |
29 times.append(time.time() - start) | 31 times.append(time.time() - start) |
30 N = float(len(times)) | 32 N = float(len(times)) |
31 avg = sum(times, 0.0) / N | 33 avg = sum(times, 0.0) / N |
32 squared_diffs = [(t - avg) * (t - avg) for t in times] | 34 squared_diffs = [(t - avg) * (t - avg) for t in times] |
33 stdev = sum(squared_diffs, 0.0) / (N - 1) | 35 stdev = sum(squared_diffs, 0.0) / (N - 1) |
34 times.sort() | 36 times.sort() |
35 percentile_75 = times[int(0.75 * N)] | 37 percentile_75 = times[int(0.75 * N)] |
36 | 38 |
37 print "%s: avg=%f; stdev=%f; min=%f; 75th percentile = %f" % ( | 39 print "%s: avg=%f; stdev=%f; min=%f; 75th percentile = %f" % ( |
38 "Round trip time (seconds)", | 40 "Round trip time (seconds)", |
39 avg, stdev, min(times), percentile_75) | 41 avg, stdev, min(times), percentile_75) |
40 | 42 |
41 return 0 | 43 return 0 |
42 | 44 |
| 45 |
43 if __name__ == '__main__': | 46 if __name__ == '__main__': |
44 sys.exit(Main(sys.argv[1:])) | 47 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |