Created
December 8, 2012 07:37
-
-
Save piglovesyou/4239149 to your computer and use it in GitHub Desktop.
Create literal vs use static
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
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
var obj = { | |
yeah: 'yeah', | |
ohh: 'ohh' | |
}; | |
var arr = [ | |
'yeah', | |
'ohh' | |
]; | |
suite.add('Object Literal', function() { | |
var o = { | |
yeah: 'yeah', | |
ohh: 'ohh' | |
}; | |
o.yeah; | |
}).add('Object Static', function() { | |
var o = obj; | |
o.yeah; | |
}).add('Array Literal', function() { | |
var a = [ | |
'yeah', | |
'ohh' | |
]; | |
a[1]; | |
}).add('Array Static', function() { | |
var a = arr; | |
a[1]; | |
}) | |
.on('cycle', function(event) { | |
console.log(event.target.toString()); | |
}).on('complete', function() { | |
console.log('----Fastest is ' + this.filter('fastest').pluck('name')); | |
}).run({ 'async': true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mac OSX 10.0.2, 2.3GHz Intel Core i7, 4GB 1600 MHz DDR 3