Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / importer / trace_event_importer_perf_test.js
1 // Copyright (c) 2013 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 'use strict';
6
7 tvcm.require('tracing.test_utils');
8 tvcm.require('tracing.importer.trace_event_importer');
9
10 tvcm.unittest.testSuite('tracing.importer.trace_event_importer_perf_test', function() { // @suppress longLineCheck
11   var eventStrings = {};
12
13   function getSynchronous(url) {
14     var req = new XMLHttpRequest();
15     req.open('GET', url, false);
16     req.send(null);
17     return req.responseText;
18   }
19
20   function getEvents(url) {
21     if (url in eventStrings)
22       return eventStrings[url];
23     eventStrings[url] = getSynchronous(url);
24     return eventStrings[url];
25   }
26
27   function timedPerfTestWithEvents(name, testFn, initialOptions) {
28     if (initialOptions.setUp)
29       throw new Error(
30           'Per-test setUp not supported. Trivial to fix if needed.');
31
32     var options = {};
33     for (var k in initialOptions)
34       options[k] = initialOptions[k];
35     options.setUp = function() {
36       ['/test_data/simple_trace.json', '/test_data/lthi_cats.json'].forEach(
37           function warmup(url) {
38             getEvents(url);
39           });
40     };
41     timedPerfTest(name, testFn, options);
42   }
43
44   var n110100 = [1, 10, 100];
45   n110100.forEach(function(val) {
46     timedPerfTestWithEvents('simple_trace_' + val, function() {
47       var events = getEvents('/test_data/simple_trace.json');
48       var m = new tracing.TraceModel();
49       m.importTraces([events], false, false);
50     }, {iterations: val});
51   });
52
53   timedPerfTestWithEvents('lthi_cats_1', function() {
54     var events = getEvents('/test_data/lthi_cats.json');
55     var m = new tracing.TraceModel();
56     m.importTraces([events], false, false);
57   }, {iterations: 1});
58 });