Bug 449371 Firefox/Thunderbird crashes at exit [@ gdk_display_x11_finalize], p=Brian...
[wine-gecko.git] / testing / performance / talos / page_load_test / jss / runner.js
blobc00524a6573d7bd9a91c7d029fb92c67a84b6560
1 (function(){
3 // Figure out if we need to stagger the tests, or not
4 var doDelay = typeof window != "undefined" && window.location && window.location.search == "?delay";
6 // Get the output pre (if it exists, and if we're embedded in a runner page)
7 var pre = typeof document != "undefined" && document.getElementsByTagName &&
8 document.getElementsByTagName("pre")[0];
10 // The number of iterations to do
11 // and the number of seconds to wait for a timeout
12 var numTests = 100, timeout = !doDelay ? 20000 : 4500;
14 var title, testName, summary = 0, queue = [];
16 // Initialize a batch of tests
17 // name = The name of the test collection
18 this.startTest = function(name){
19 testName = name;
21 if ( typeof onlyName == "undefined" )
22 log([ "__start_report", testName ]);
25 // End the tests and finalize the report
26 this.endTest = function(){
27 // Save the summary output until all the test are complete
28 queue.push(function(){
29 if ( typeof onlyName == "undefined" ) {
30 log([ "__summarystats", summary ]);
31 log([ "__end_report" ]);
33 // Log the time to the special Talos function, if it exists
34 } else if ( typeof tpRecordTime != "undefined" )
35 tpRecordTime( summary );
37 // Otherwise, we're only interested in the results from a single function
38 else
39 log([ "__start_report" + summary + "__end_report" ]);
41 // Force an application quit (for the Mozilla perf test runner)
42 if ( typeof goQuitApplication != "undefined" )
43 goQuitApplication();
44 });
46 // Start running the first test
47 dequeue();
50 // Run a new test
51 // name = The unique name of the test
52 // num = The 'length' of the test (length of string, # of tests, etc.)
53 // fn = A function holding the test to run
54 this.test = function(name, num, fn){
55 // Done't run the test if we're limiting to just one
56 if ( typeof onlyName == "undefined" || (name == onlyName && num == onlyNum) ) {
57 // Don't execute the test immediately
58 queue.push(function(){
59 doTest( name, num, fn );
60 });
64 // The actual testing function (only to be called via the queue control)
65 function doTest(name, num, fn){
66 title = name;
67 var times = [], start, diff, sum = 0, min = -1, max = -1,
68 median, std, mean;
70 if ( !fn ) {
71 fn = num;
72 num = '';
75 // run tests
76 try {
77 // We need to let the test time out
78 var testStart = (new Date()).getTime();
80 for ( var i = 0; i < numTests; i++ ) {
81 start = (new Date()).getTime();
82 fn();
83 var cur = (new Date()).getTime();
84 diff = cur - start;
86 // Make Sum
87 sum += diff;
89 // Make Min
90 if ( min == -1 || diff < min )
91 min = diff;
93 // Make Max
94 if ( max == -1 || diff > max )
95 max = diff;
97 // For making Median and Variance
98 times.push( diff );
100 // Check to see if the test has run for too long
101 if ( timeout > 0 && cur - testStart > timeout )
102 break;
104 } catch( e ) {
105 if ( typeof onlyName == "undefined" )
106 return log( [ title, num, NaN, NaN, NaN, NaN, NaN ] );
107 else
108 return log( [ "__FAIL" + e + "__FAIL" ] );
111 // Make Mean
112 mean = sum / times.length;
114 // Keep a running summary going
115 summary += mean;
117 // Make Median
118 times = times.sort(function(a,b){
119 return a - b;
122 if ( times.length % 2 == 0 )
123 median = (times[(times.length/2)-1] + times[times.length/2]) / 2;
124 else
125 median = times[(times.length/2)];
127 // Make Variance
128 var variance = 0;
129 for ( var i = 0; i < times.length; i++ )
130 variance += Math.pow(times[i] - mean, 2);
131 variance /= times.length - 1;
133 // Make Standard Deviation
134 std = Math.sqrt( variance );
136 if ( typeof onlyName == "undefined" )
137 log( [ title, num, median, mean, min, max, std ] );
139 // Execute the next test
140 dequeue();
143 // Remove the next test from the queue and execute it
144 function dequeue(){
145 // If we're in a browser, and the user wants to delay the tests,
146 // then we should throw it in a setTimeout
147 if ( doDelay && typeof setTimeout != "undefined" )
148 setTimeout(function(){
149 queue.shift()();
150 }, 13);
152 // Otherwise execute the test immediately
153 else
154 queue.shift()();
157 // Log the results
158 function log( arr ) {
159 // If we're in an embedded runner, output to the output pre
160 if ( pre )
161 pre.innerHTML += arr.join(":") + "\n";
163 // Otherwise, just document.write out the results
164 else if ( typeof document != "undefined" && document.write && !doDelay )
165 document.write( arr.join(":") + "\n" );
167 // Otherwise, we're probably in a shell of some sort
168 else if ( typeof window == "undefined" && typeof print != "undefined" )
169 print( arr.join(":") );
172 })();