Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add key/value iterable HTML benchmark
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |