Skip to content

Instantly share code, notes, and snippets.

@wejrowski
Last active March 23, 2016 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wejrowski/fdef97e4729a5f0d1de5 to your computer and use it in GitHub Desktop.
Save wejrowski/fdef97e4729a5f0d1de5 to your computer and use it in GitHub Desktop.
Benchmark template
/**
* Simple benchmark copy paste for browsers using Benchmark.js
* See their documentation: https://benchmarkjs.com/
* Edit the different suite add() sections below to change your tests or add new ones.
*/
var Script = function(url) {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = url;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
}
addScript("https://rawgit.com/lodash/lodash/4.6.1/dist/lodash.js");
addScript("https://rawgit.com/bestiejs/platform.js/master/platform.js");
addScript("https://rawgit.com/bestiejs/benchmark.js/master/benchmark.js");
var suite = new Benchmark.Suite;
suite.add('push test', function() {
var a = [], b = [], i;
for (i=0; i<1000; i++) {
a[i] = {somea: 'object' + i};
}
for (i=0; i<1000; i++) {
b[i] = {someb: 'object' + i};
}
a.push.apply(a, b);
})
.add('splice test', function() {
var a = [], b = [], i;
for (i=0; i<1000; i++) {
a[i] = {somea: 'object' + i};
}
for (i=0; i<1000; i++) {
b[i] = {someb: 'object' + i};
}
a.splice.apply(a, [a.length, 0].concat(b))
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment