Commit 5878fac5 authored by abarth@webkit.org's avatar abarth@webkit.org

2010-12-31 Patrick Gansterer <paroga@webkit.org>

        Reviewed by Adam Barth.

        Add XML parser benchmark
        https://bugs.webkit.org/show_bug.cgi?id=51612

        Move the JavaScript code of html parser into a separate file to share it with xml parser.

        * benchmarks/parser/html-parser.html:
        * benchmarks/parser/resources/runner.js: Copied from WebCore/benchmarks/parser/html-parser.html.
        (runFunction):
        (run):
        (start):
        * benchmarks/parser/xml-parser.html: Copied from WebCore/benchmarks/parser/html-parser.html.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74824 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c871a7fa
2010-12-31 Patrick Gansterer <paroga@webkit.org>
Reviewed by Adam Barth.
Add XML parser benchmark
https://bugs.webkit.org/show_bug.cgi?id=51612
Move the JavaScript code of html parser into a separate file to share it with xml parser.
* benchmarks/parser/html-parser.html:
* benchmarks/parser/resources/runner.js: Copied from WebCore/benchmarks/parser/html-parser.html.
(runFunction):
(run):
(start):
* benchmarks/parser/xml-parser.html: Copied from WebCore/benchmarks/parser/html-parser.html.
2010-12-29 Zhenyao Mo <zmo@google.com>
Reviewed by Kenneth Russell.
......
<!DOCTYPE html>
<body>
<pre id="log"></pre>
<script src="resources/runner.js"></script>
<script>
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 spec = loadFile("resources/html5.html");
function parse(html) {
start(20, function() {
var iframe = document.createElement("iframe");
iframe.src = "about:blank";
iframe.style.display = "none";
document.body.appendChild(iframe)
document.body.appendChild(iframe);
iframe.contentDocument.open();
iframe.contentDocument.write(html);
iframe.contentDocument.write(spec);
iframe.contentDocument.close();
document.body.removeChild(iframe)
}
var runCount = 20;
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)
parse(spec);
var time = new Date() - start;
completedRuns++;
if (completedRuns <= 0) {
log("Ignoring warm-up run (" + time + ")");
} else {
times.push(time);
log(time);
}
if (completedRuns < runCount) {
window.setTimeout(run, 0);
} else {
logStatistics(times);
}
}
log("Running " + runCount + " times");
run();
document.body.removeChild(iframe);
});
</script>
</body>
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();
}
<!DOCTYPE html>
<body>
<pre id="log"></pre>
<script src="resources/runner.js"></script>
<script>
var domParser = new DOMParser();
var xmlArray = [];
xmlArray.push('<root>');
for (var i = 0; i < 0x7FFF; ++i)
xmlArray.push('<item attribute1="value1" attribute2="value2" attribute3="value3" attribute4="value4" attribute5="value5" />');
xmlArray.push('</root>')
var xmlData = xmlArray.join('');
start(20, function() {
domParser.parseFromString(xmlData, "text/xml");
});
</script>
</body>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment