Skip to content

Instantly share code, notes, and snippets.

@Nepoxx
Created June 7, 2016 15:14
Show Gist options
  • Save Nepoxx/4abba489e5db63a6d1ca670d572efba6 to your computer and use it in GitHub Desktop.
Save Nepoxx/4abba489e5db63a6d1ca670d572efba6 to your computer and use it in GitHub Desktop.
'use strict';
const Benchmark = require('benchmark');
const benchmarkOutput = require('beautify-benchmark');
var suite = new Benchmark.Suite;
function litteral() {
return {
a: 3,
b: 5,
c: 6
};
}
function generateObject(a) {
return {
a: a,
b: 5,
c: 6
};
}
function useGenerator() {
return generateObject(3);
}
function construct(a) {
this.a = a;
this.b = 5;
this.c = 6;
}
function useConstructor() {
return new construct(3);
}
suite.add('constructor', () => {
useConstructor();
});
suite.add('literal', () => {
litteral();
});
suite.add('generator', () => {
useGenerator();
});
suite.on('cycle', event => {
benchmarkOutput.add(event.target);
})
suite.on('complete', function () {
benchmarkOutput.log();
});
suite.run();
constructor x 132,417,608 ops/sec ±1.36% (91 runs sampled)
literal x 132,574,448 ops/sec ±1.54% (91 runs sampled)
generator x 129,888,410 ops/sec ±0.74% (93 runs sampled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment