Skip to content

Instantly share code, notes, and snippets.

@brn
Created February 23, 2018 08:45
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 brn/8beefffb5efa99862b6ce35d20f72988 to your computer and use it in GitHub Desktop.
Save brn/8beefffb5efa99862b6ce35d20f72988 to your computer and use it in GitHub Desktop.
/**
* @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