Created
February 23, 2018 08:45
-
-
Save brn/8beefffb5efa99862b6ce35d20f72988 to your computer and use it in GitHub Desktop.
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
/** | |
* @fileoverview | |
* @author Taketoshi Aono | |
*/ | |
const fs = require('fs'); | |
const LOOP_COUNT = 1e6; | |
function generatorBenchmark(filename, cb) { | |
const fd = fs.openSync(filename, 'w'); | |
fs.appendFileSync(fd, `const start = Date.now();eval("`); | |
cb(fd); | |
fs.appendFileSync(fd, '");console.log(`${Date.now() - start}ms.`);'); | |
fs.closeSync(fd); | |
} | |
generatorBenchmark('benchmark-separator.js', fd => { | |
for (let i = 0; i < LOOP_COUNT; i++) { | |
fs.appendFileSync( | |
fd, [ | |
"1_0_0_0", | |
"1_0e+1", | |
"1_0e+1_0", | |
"0xF_F_FF", | |
"0o7_7_7", | |
"0b0_1_0_1_0", | |
".3_2_1", | |
"0.0_2_1", | |
"1_0.0_1", | |
".0_1_2" | |
].join(';')); | |
} | |
}); | |
generatorBenchmark('benchmark-normal.js', fd => { | |
for (let i = 0; i < LOOP_COUNT; i++) { | |
fs.appendFileSync( | |
fd, [ | |
"1000", | |
"10e+1", | |
"10e+10", | |
"0xFFFF", | |
"0o777", | |
"0b01010", | |
".321", | |
"0.021", | |
"10.01", | |
".012" | |
].join(';')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment