summaryrefslogtreecommitdiffstats
path: root/PerformanceTests/Parser/resources/runner.js
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-06 11:45:16 +0100
committerSteve Block <steveblock@google.com>2011-05-12 13:44:10 +0100
commitcad810f21b803229eb11403f9209855525a25d57 (patch)
tree29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /PerformanceTests/Parser/resources/runner.js
parent121b0cf4517156d0ac5111caf9830c51b69bae8f (diff)
downloadexternal_webkit-cad810f21b803229eb11403f9209855525a25d57.zip
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'PerformanceTests/Parser/resources/runner.js')
-rw-r--r--PerformanceTests/Parser/resources/runner.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/PerformanceTests/Parser/resources/runner.js b/PerformanceTests/Parser/resources/runner.js
new file mode 100644
index 0000000..4baa497
--- /dev/null
+++ b/PerformanceTests/Parser/resources/runner.js
@@ -0,0 +1,95 @@
+function log(text) {
+ document.getElementById("log").innerText += text + "\n";
+ window.scrollTo(document.body.height);
+}
+
+function loadFile(path) {
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", path, false);
+ xhr.send(null);
+ return xhr.responseText;
+}
+
+var runCount = -1;
+var runFunction = function() {};
+var completedRuns = -1; // Discard the any runs < 0.
+var times = [];
+
+function computeAverage(values) {
+ var sum = 0;
+ for (var i = 0; i < values.length; i++)
+ sum += values[i];
+ return sum / values.length;
+}
+
+function computeMax(values) {
+ var max = values.length ? values[0] : 0;
+ for (var i = 1; i < values.length; i++) {
+ if (max < values[i])
+ max = values[i];
+ }
+ return max;
+}
+
+function computeMedian(values) {
+ values.sort(function(a, b) { return a - b; });
+ var len = values.length;
+ if (len % 2)
+ return values[(len-1)/2];
+ return (values[len/2-1] + values[len/2]) / 2;
+}
+
+function computeMin(values) {
+ var min = values.length ? values[0] : 0;
+ for (var i = 1; i < values.length; i++) {
+ if (min > values[i])
+ min = values[i];
+ }
+ return min;
+}
+
+function computeStdev(values) {
+ var average = computeAverage(values);
+ var sumOfSquaredDeviations = 0;
+ for (var i = 0; i < values.length; ++i) {
+ var deviation = values[i] - average;
+ sumOfSquaredDeviations += deviation * deviation;
+ }
+ return Math.sqrt(sumOfSquaredDeviations / values.length);
+}
+
+function logStatistics(times) {
+ log("");
+ log("avg " + computeAverage(times));
+ log("median " + computeMedian(times));
+ log("stdev " + computeStdev(times));
+ log("min " + computeMin(times));
+ log("max " + computeMax(times));
+}
+
+function run() {
+ var start = new Date();
+ for (var i = 0; i < 10; ++i)
+ window.runFunction();
+ var time = new Date() - start;
+ completedRuns++;
+ if (completedRuns <= 0) {
+ log("Ignoring warm-up run (" + time + ")");
+ } else {
+ times.push(time);
+ log(time);
+ }
+ if (completedRuns < window.runCount) {
+ window.setTimeout(run, 0);
+ } else {
+ logStatistics(times);
+ }
+}
+
+function start(runCount, runFunction) {
+ window.runCount = runCount;
+ window.runFunction = runFunction;
+
+ log("Running " + runCount + " times");
+ run();
+}