Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created January 9, 2014 22:02
Show Gist options
  • Save mraleph/8342886 to your computer and use it in GitHub Desktop.
Save mraleph/8342886 to your computer and use it in GitHub Desktop.
function BenchmarkRun() {
// Benchmark.prototype.setup goes here
obj = {
"apples": true,
"oranges": true,
"pears": true,
"pinapples": true,
"grapes": true,
}
array = [
"apples",
"oranges",
"pears",
"pinapples",
"grapes",
]
var start = new Date;
for (...) { // do N iterations of test body
delete obj.pears
}
var end = new Date;
// Performance is expressed in runs per second: N / ((start - end) / 1000)
// But notice how only the first run of the loop actually deletes something
// at subsequent iterations property has been already deleted. Which makes
// resulting metrics reflect more "how much does it cost to *not* delete a property"
// then what you really wanted to measure
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment