Skip to content

Commit

Permalink
Add key/value iterable HTML benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Mar 18, 2018
1 parent 64dc0c4 commit 30fb15d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/html/pair_iterable_perf.html
@@ -0,0 +1,44 @@
<!doctype html>
<meta charset="utf-8">
<title>Value and pair iterable bindings</title>
<script>
// Requires passing --pref=dom.testbinding.enabled to Servo binary
function collect(iter) {
var collection = [];
for (element of iter) {
collection.push(element);
}
return collection;
}

function measure_time(func) {
var start = performance.now();
func();
var stop = performance.now();

return (stop - start) / 1000.0;
};

const ENTRY_COUNT = 10000;
const RUN_COUNT = 10;

var benchMe = function() {
var t = new TestBindingPairIterable();

for (var i = 0; i < ENTRY_COUNT; i++) {
t.add(i.toString(), i);
}

var result = collect(t.entries());
};

var avg = 0;
for (var i = 0; i < RUN_COUNT; i++) {
var time = measure_time(benchMe);
avg += time;
}
avg /= RUN_COUNT;

console.log('Average running time across ' + RUN_COUNT + ' runs: ' + avg);

</script>

0 comments on commit 30fb15d

Please sign in to comment.