Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from danielo515/feature/benchmarks
chore(perf): added benchmarks for detect regresions
- Loading branch information
Showing
13 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ dist | |
node_modules | ||
coverage | ||
*.log | ||
package-lock.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "5" | ||
- "6" | ||
- "8" | ||
- "9" | ||
script: | ||
- npm run lint:test | ||
- 'bash bin/run_report.sh' | ||
cache: | ||
yarn: true | ||
directories: | ||
- node_modules | ||
after_success: 'npm run coveralls' | ||
after_success: | ||
- 'npm run coveralls' | ||
- 'bash bin/commit.sh' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
a: { | ||
b: { | ||
c: { | ||
a: `This is a`, | ||
b: `This is b` | ||
} | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const Suite = require(`benchmarked`); | ||
const suite = new Suite({ | ||
cwd: __dirname, // optionally define a base directory for code and fixtures | ||
fixtures: `../fixtures/*.js`, // path or glob pattern to fixtures | ||
code: `src/*.js`, // path or glob pattern to code files | ||
}); | ||
|
||
// run the benchmarks | ||
suite.run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const OT = require(`../../../src`); | ||
|
||
const map = { | ||
a: `a.b.c.a`, | ||
b: `a.b.c.b` | ||
}; | ||
|
||
module.exports = OT(map); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const OT = require(`../../../src`); | ||
|
||
const map = { | ||
a: `a.b.c.a`, | ||
b: `a.b.c.b`, | ||
x: `a.b.c.x` | ||
}; | ||
|
||
const defaults = { | ||
a: { | ||
b: { | ||
c: { | ||
x: `X not defined` | ||
} | ||
} | ||
} | ||
}; | ||
|
||
|
||
module.exports = OT(map, defaults); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const Runner = require(`benchr`); | ||
const reporter = require(`./reporter`); | ||
const runOptions = {progress: false, reporter, verbose: false, maxTime: 5, minTime: 0, delay: 0}; | ||
// The json reporter uses console.log to report, so we just cheat here | ||
new Runner(runOptions, `${__dirname}/src/_basic.js`).run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const {platform} = require(`benchmark`); | ||
const nVersion = `N${platform.version}`; | ||
const {version} = require(`../../package`); | ||
const report = require(`../report`); | ||
const {promisify} = require(`util`); | ||
const {writeFile: _writeFile} = require(`fs`); | ||
const {join} = require(`path`); | ||
const writeFile = promisify(_writeFile); | ||
const curDir = x => join(__dirname, x); | ||
|
||
module.exports = runner => { | ||
|
||
// Handle runner events. | ||
let currentFile, currentSuite; | ||
const stats = {platform, files: []}; | ||
runner.on(`run.start`, () => { | ||
stats.started = new Date(); | ||
}).on(`file.start`, file => { | ||
currentFile = { | ||
name: file, | ||
suites: [], | ||
}; | ||
stats.files.push(currentFile); | ||
}).on(`suite.start`, suite => { | ||
currentSuite = { | ||
name: suite.name, | ||
benchmarks: [], | ||
}; | ||
currentFile.suites.push(currentSuite); | ||
}).on(`suite.complete`, suite => { | ||
|
||
// Add the name(s) of the fastest benchmark(s). | ||
currentSuite.fastest = suite.filter(`fastest`).map(`name`); | ||
// Handle benchmark statistics. | ||
currentSuite.benchmarks = suite.map(bench => { | ||
delete bench.stats.sample; | ||
return { | ||
name: bench.name, | ||
hz: bench.hz, | ||
aborted: bench.aborted, | ||
stats: bench.stats, | ||
}; | ||
}); | ||
}).on(`run.complete`, () => { | ||
stats.ended = new Date(); | ||
report[nVersion] = Object.assign({}, report[nVersion], {[version]: stats}); | ||
writeFile(curDir(`../report.json`), JSON.stringify(report, null, 2), `utf8`).then(console.log(`Benchmark Finished`)); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const small = require(`../../fixtures/small`); | ||
const OT = require(`../../../src`); | ||
|
||
const map = { | ||
a: `a.b.c.a`, | ||
b: `a.b.c.b` | ||
}; | ||
|
||
const triggerDefaults = Object.assign({}, map, {x: `a.b.c.x`}); | ||
|
||
const defaults = { | ||
a: { | ||
b: { | ||
c: { | ||
x: `X not defined` | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const basic = OT(map); | ||
const withDefaults = OT(triggerDefaults, defaults); | ||
|
||
module.exports = (suite, benchmark) => { | ||
|
||
suite(`4 nest levels`, () => { | ||
|
||
benchmark(`Basic converter`, () => basic(small)); | ||
benchmark(`Using defaults`, () => withDefaults(small)); | ||
|
||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"N8.9.4": { | ||
"1.0.0": { | ||
"platform": { | ||
"description": "Node.js 8.9.4 on Win32 64-bit", | ||
"layout": null, | ||
"manufacturer": null, | ||
"name": "Node.js", | ||
"prerelease": null, | ||
"product": null, | ||
"ua": null, | ||
"version": "8.9.4", | ||
"os": { | ||
"architecture": 64, | ||
"family": "Win32", | ||
"version": null | ||
} | ||
}, | ||
"files": [ | ||
{ | ||
"name": "C:\\Users\\rdani\\Dropbox\\programacion\\node\\object-translate\\__benchmarks__\\report-json/src/_basic.js", | ||
"suites": [ | ||
{ | ||
"name": "4 nest levels", | ||
"benchmarks": [ | ||
{ | ||
"name": "Basic converter", | ||
"hz": 165640.18594310517, | ||
"aborted": false, | ||
"stats": { | ||
"moe": 1.4346621272262202e-7, | ||
"rme": 2.3763770151928187, | ||
"sem": 7.319704730746022e-8, | ||
"deviation": 6.944081624720084e-7, | ||
"mean": 0.0000060371823075801454, | ||
"variance": 4.822026961077513e-13 | ||
} | ||
}, | ||
{ | ||
"name": "Using defaults", | ||
"hz": 103028.45682340284, | ||
"aborted": false, | ||
"stats": { | ||
"moe": 2.2288888017834302e-7, | ||
"rme": 2.296389736787102, | ||
"sem": 1.1371881641752195e-7, | ||
"deviation": 0.00000112000045228473, | ||
"mean": 0.000009706056276413632, | ||
"variance": 1.2544010131179996e-12 | ||
} | ||
} | ||
], | ||
"fastest": [ | ||
"Basic converter" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"started": "2018-05-26T12:17:53.847Z", | ||
"ended": "2018-05-26T12:18:07.051Z" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
node_version=$(node -v); | ||
|
||
function msg() { | ||
echo "travis-commit: $*" | ||
} | ||
|
||
function err() { | ||
msg "$*" 1>&2 | ||
} | ||
|
||
if [ ${node_version:1:1} -lt 8 ]; then | ||
err "Nothing to commit on node 6" | ||
exit 0 | ||
fi | ||
git add __benchmarks__/* | ||
# make Travis CI skip this build | ||
if ! git commit -m "Travis CI update [ci skip]"; then | ||
err "failed to commit updates" | ||
exit 1 | ||
fi | ||
|
||
remote=https://$GITHUB_TOKEN@github.com/$TRAVIS_REPO_SLUG | ||
|
||
if ! git push --follow-tags "$remote" "$TRAVIS_BRANCH" > /dev/null 2>&1; then | ||
err "failed to push git changes to $remote $TRAVIS_BRANCH" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
node_version=$(node -v); | ||
if [ ${node_version:1:1} -gt 6 ]; then | ||
npm run benchmark:report | ||
fi |
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