| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """DoYouEvenBench performance benchmark . | 5 """DoYouEvenBench performance benchmark . |
| 6 | 6 |
| 7 DoYouEvenBench performance benchmark UI performance related to DOM using | 7 DoYouEvenBench performance benchmark UI performance related to DOM using |
| 8 popular JS frameworks. This benchmark uses http://todomvc.com and emulates user | 8 popular JS frameworks. This benchmark uses http://todomvc.com and emulates user |
| 9 actions: adding 100 todo items, completing them, and then deleting | 9 actions: adding 100 todo items, completing them, and then deleting |
| 10 them with Ember.js, Backbone.js, jQuery, and plain-old DOM. | 10 them with Ember.js, Backbone.js, jQuery, and plain-old DOM. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import os | 13 import os |
| 14 | 14 |
| 15 from telemetry import test | 15 from telemetry import test |
| 16 from telemetry.page import page_measurement | 16 from telemetry.page import page_measurement |
| 17 from telemetry.page import page_set | 17 from telemetry.page import page_set |
| 18 from telemetry.value import scalar | 18 from telemetry.value import scalar |
| 19 | 19 |
| 20 | 20 |
| 21 class DoYouEvenBenchMeasurement(page_measurement.PageMeasurement): | 21 class DoYouEvenBenchMeasurement(page_measurement.PageMeasurement): |
| 22 | 22 |
| 23 def MeasurePage(self, _, tab, results): | 23 def MeasurePage(self, _, tab, results): |
| 24 tab.WaitForDocumentReadyStateToBeComplete() | 24 tab.WaitForDocumentReadyStateToBeComplete() |
| 25 # Click Run button on http://rniwa.com/DoYouEvenBench to start test. | 25 # Tests are ran 5 iteration, results are displayed in the form of HTML |
| 26 tab.ExecuteJavaScript('document.getElementsByTagName("button")[1].click();') | 26 # table. Each row represents timetaken in that iteration and adds rows for |
| 27 # <PRE> tag stores the results once the tests are completed. | 27 # Arithmetic Mean and 95th Percentile. Total 7 rows in the results table. |
| 28 tab.WaitForJavaScriptExpression( | 28 tab.WaitForJavaScriptExpression( |
| 29 'document.getElementsByTagName("pre").length > 0', 200) | 29 'document.getElementsByTagName("tr").length >= 7', 200) |
| 30 # Parse results | 30 # Parse results and result for each run including mean and 95th percentile. |
| 31 results_log = tab.EvaluateJavaScript( | 31 js_results = """ function JsResults() { |
| 32 'document.getElementsByTagName("pre")[0].innerHTML') | 32 var _result = {} |
| 33 res_log = results_log.splitlines() | 33 _rows = document.getElementsByTagName("tr"); |
| 34 for res in res_log: | 34 for(var i=0; i< _rows.length; i++) { |
| 35 name_and_score = res.split(': ', 2) | 35 if (_rows[i].cells[0].innerText.indexOf("95th Percentile") == -1) { |
| 36 assert len(name_and_score) == 2, 'Unexpected result format "%s"' % res | 36 _result[_rows[i].cells[0].innerText] = _rows[i].cells[1].innerText; |
| 37 # Replace '/' with '_' for quantity being measure otherwise it asserts | 37 } |
| 38 # while printing results to stdout. | 38 } |
| 39 name = name_and_score[0].replace('/', '_').strip() | 39 return _result; |
| 40 score = float(name_and_score[1].replace('ms', '').strip()) | 40 }; JsResults();""" |
| 41 # Since Total consists total time taken by all tests, add its values | 41 results_log = tab.EvaluateJavaScript(js_results) |
| 42 # to Summary. | 42 for name, value in results_log.iteritems(): |
| 43 if 'Total' not in name: | 43 score = float(value.replace('ms', '').strip()) |
| 44 # Add time taken for each iteration to run tests. |
| 45 if name != 'Arithmetic Mean': |
| 44 results.Add(name, 'ms', score, data_type='unimportant') | 46 results.Add(name, 'ms', score, data_type='unimportant') |
| 45 else: | 47 else: |
| 46 results.AddSummaryValue(scalar.ScalarValue(None, 'Total', 'ms', score)) | 48 results.AddSummaryValue(scalar.ScalarValue(None, name, 'ms', score)) |
| 47 | |
| 48 | 49 |
| 49 class DoYouEvenBench(test.Test): | 50 class DoYouEvenBench(test.Test): |
| 50 """DoYouEvenBench benchmark related to DOMs using JS frameworks.""" | 51 """DoYouEvenBench benchmark related to DOMs using JS frameworks.""" |
| 51 test = DoYouEvenBenchMeasurement | 52 test = DoYouEvenBenchMeasurement |
| 52 | 53 |
| 53 def CreatePageSet(self, options): | 54 def CreatePageSet(self, options): |
| 54 return page_set.PageSet.FromDict({ | 55 ps = page_set.PageSet( |
| 55 'archive_data_file': '../page_sets/data/doyouevenbench.json', | 56 file_path=os.path.abspath(__file__), |
| 56 'make_javascript_deterministic': False, | 57 archive_data_file='../page_sets/data/doyouevenbench.json', |
| 57 'pages': [ | 58 make_javascript_deterministic=False) |
| 58 {'url': 'http://rniwa.com/DoYouEvenBench/'} | 59 ps.AddPageWithDefaultRunNavigate( |
| 59 ] | 60 'https://trac.webkit.org/export/164157/trunk/' |
| 60 }, os.path.abspath(__file__)) | 61 'PerformanceTests/DoYouEvenBench/Full.html') |
| 61 | 62 return ps |
| OLD | NEW |