-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): use existing benchmark.js suites
refs #8
- Loading branch information
1 parent
85fea14
commit e2e731f
Showing
12 changed files
with
150 additions
and
68 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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"xo": { | ||
"envs": [ | ||
"browser", | ||
"jasmine", | ||
"node" | ||
], | ||
"space": 2 | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,4 @@ | ||
module.exports = { | ||
Benchmark: global.Benchmark, | ||
lodash: global._ | ||
}; |
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,12 @@ | ||
module.exports = function construct(Instance, a, b, c) { | ||
if (c) { | ||
return new Instance(a, b, c); | ||
} | ||
if (b) { | ||
return new Instance(a, b); | ||
} | ||
if (a) { | ||
return new Instance(a); | ||
} | ||
return new Instance(); | ||
}; |
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,3 +1,17 @@ | ||
module.exports = function karmaBenchmark() { | ||
// temp... | ||
// 3rd party modules | ||
var karma = require('./vendor/karma'); | ||
|
||
// modules | ||
var runBenchmarks = require('./run-benchmarks'); | ||
var WrappedBenchmark = require('./wrapped-benchmark'); | ||
|
||
// implementation | ||
global.Benchmark = WrappedBenchmark; | ||
|
||
karma.start = function () { | ||
runBenchmarks(function () { | ||
karma.complete({ | ||
coverage: global.__coverage__ | ||
}); | ||
}); | ||
}; |
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,55 @@ | ||
// 3rd party modules | ||
var karma = require('./vendor/karma'); | ||
|
||
// modules | ||
var store = require('./store'); | ||
|
||
// public | ||
module.exports = runBenchmarks; | ||
|
||
// implementation | ||
function runBenchmarks(done) { | ||
var suites = store.getSuites(); | ||
if (suites.length) { | ||
runSuite(suites.shift(), function () { | ||
runBenchmarks(done); | ||
}); | ||
} else { | ||
done(); | ||
} | ||
} | ||
|
||
function runSuite(suite, done) { | ||
var errors = []; | ||
suite | ||
.on('cycle', function (e) { | ||
karma.result({ | ||
id: e.target.id, | ||
description: suite.name + ': ' + e.target.name, | ||
suite: [], | ||
success: errors.length === 0, | ||
log: errors, | ||
skipped: false, | ||
time: e.target.stats.mean * 1000, | ||
benchmark: { | ||
suite: suite.name, | ||
name: e.target.name, | ||
stats: e.target.stats, | ||
count: e.target.count, | ||
cycles: e.target.cycles, | ||
error: e.target.error, | ||
hz: e.target.hz | ||
} | ||
}); | ||
errors = []; | ||
}) | ||
.on('abort error', function (e) { | ||
errors.push(e.target.error.toString()); | ||
}) | ||
.on('complete', | ||
done | ||
) | ||
.run({ | ||
async: true | ||
}); | ||
} |
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,27 @@ | ||
// public | ||
module.exports = { | ||
addBenchmark: addBenchmark, | ||
addSuite: addSuite, | ||
getSuites: getSuites | ||
}; | ||
|
||
// implementation | ||
var benchmarks = []; | ||
var suites = []; | ||
|
||
function addBenchmark(benchmark, hasSuite) { | ||
benchmark.hasSuite = Boolean(hasSuite); | ||
benchmarks.push(benchmark); | ||
console.log('benchmark added:', benchmark, benchmarks); | ||
return benchmark; | ||
} | ||
|
||
function addSuite(suite) { | ||
suites.push(suite); | ||
console.log('suite added:', suite, suites); | ||
return suite; | ||
} | ||
|
||
function getSuites() { | ||
return suites; | ||
} |
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 @@ | ||
module.exports = global.Benchmark; |
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 @@ | ||
module.exports = global.__karma__; |
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 @@ | ||
module.exports = global._; |
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,32 @@ | ||
// 3rd party modules | ||
var Benchmark = require('./vendor/Benchmark'); | ||
|
||
// modules | ||
var construct = require('./lib/construct'); | ||
var store = require('./store'); | ||
|
||
// public | ||
module.exports = WrappedBenchmark; | ||
module.exports.Suite = WrappedSuite; | ||
|
||
// implementation | ||
var Suite = Benchmark.Suite; | ||
|
||
function WrappedBenchmark(name, fn, options) { | ||
var benchmark = construct(Benchmark, name, fn, options); | ||
return store.addBenchmark(benchmark, false); | ||
} | ||
|
||
function WrappedSuite(name, options) { | ||
var suite = construct(Suite, name, options); | ||
suite.add = addBenchmark; | ||
store.addSuite(suite); | ||
return suite; | ||
} | ||
|
||
function addBenchmark(name, fn, options) { | ||
var suite = Suite.prototype.add.call(this, name, fn, options); | ||
var benchmark = suite[suite.length - 1]; | ||
store.addBenchmark(benchmark, true); | ||
return suite; | ||
} |