Skip to content

Instantly share code, notes, and snippets.

@schnittstabil
Last active October 9, 2015 19:18
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 schnittstabil/ddd265bcfdeda7fab087 to your computer and use it in GitHub Desktop.
Save schnittstabil/ddd265bcfdeda7fab087 to your computer and use it in GitHub Desktop.
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
global.minOps = 1024;
global.undersized = new Buffer(3);
global.exactSize = new Buffer(global.minOps);
function access(buff, size) {
for (var i = 0; i < size; i++) {
buff[i];
}
}
suite
.add("undersized ", function () {
access(global.undersized, global.minOps);
})
.add("exact length", function () {
access(global.exactSize, global.minOps);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run();
@schnittstabil
Copy link
Author

My result:

$ node buffer-access-benchmark.js 
undersized   x 7,304 ops/sec ±0.84% (97 runs sampled)
exact length x 4,597 ops/sec ±0.70% (100 runs sampled)
Fastest is undersized  
$ node --version
v4.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment