Created
June 7, 2016 15:14
-
-
Save Nepoxx/4abba489e5db63a6d1ca670d572efba6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'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(); |
This file contains hidden or 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
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