-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51b3524
commit 0099117
Showing
8 changed files
with
164 additions
and
76 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 |
---|---|---|
|
@@ -24,3 +24,5 @@ node_modules | |
|
||
# Mac OS X DS_Store | ||
.DS_Store | ||
|
||
benchmarks/runInBrowser.bundle.js |
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 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Benchmarks</title> | ||
</head> | ||
<body> | ||
<div id="results"></div> | ||
<div id="loader">Wait please…</div> | ||
</body> | ||
</html> | ||
<script src="runInBrowser.bundle.js"></script> |
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,29 @@ | ||
var fixtures = [ | ||
{ | ||
description: 'strings', | ||
args: ['one', 'two', 'three'], | ||
expected: 'one two three' | ||
}, | ||
{ | ||
description: 'object', | ||
args: [{one: true, two: true, three: false}], | ||
expected: 'one two' | ||
}, | ||
{ | ||
description: 'strings, object', | ||
args: ['one', 'two', {four: true, three: false}], | ||
expected: 'one two four' | ||
}, | ||
{ | ||
description: 'mix', | ||
args: ['one', {two: true, three: false}, {four: 'four', five: true}, 6, {}], | ||
expected: 'one two four five 6' | ||
}, | ||
{ | ||
description: 'arrays', | ||
args: [['one', 'two'], ['three'], ['four', ['five']], [{six: true}, {seven: false}]], | ||
expected: 'one two three four five six' | ||
} | ||
]; | ||
|
||
module.exports = fixtures; |
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,97 +1,33 @@ | ||
var fixtures = [ | ||
{ | ||
description: 'strings', | ||
args: ['one', 'two', 'three'], | ||
expected: 'one two three' | ||
}, | ||
{ | ||
description: 'object', | ||
args: [{ one: true, two: true, three: false }], | ||
expected: 'one two' | ||
}, | ||
{ | ||
description: 'strings, object', | ||
args: ['one', 'two', { four: true, three: false }], | ||
expected: 'one two four' | ||
}, | ||
{ | ||
description: 'mix', | ||
args: ['one', { two: true, three: false }, { four: 'four', five: true }, 6, {}], | ||
expected: 'one two four five 6' | ||
}, | ||
{ | ||
description: 'arrays', | ||
args: [['one', 'two'], ['three'], ['four', ['five']], [{ six: true }, { seven: false }]], | ||
expected: 'one two three four five six' | ||
} | ||
]; | ||
|
||
var fixtures = require('./fixtures'); | ||
var local = require('../'); | ||
var dedupe = require('../dedupe'); | ||
var localPackage = require('../package.json'); | ||
|
||
function log (message) { | ||
console.log(message); | ||
} | ||
|
||
try { | ||
var npm = require('classnames'); | ||
var npmDedupe = require('classnames/dedupe'); | ||
var npmPackage = require('./node_modules/classnames/package.json'); | ||
} catch (e) { | ||
console.log('There was an error loading the benchmark classnames package.\n' + | ||
log('There was an error loading the benchmark classnames package.\n' + | ||
'Please make sure you have run `npm install` in ./benchmarks\n'); | ||
process.exit(0); | ||
} | ||
|
||
if (localPackage.version !== npmPackage.version) { | ||
console.log('Your local version (' + localPackage.version + ') does not match the installed version (' + npmPackage.version + ')\n\n' + | ||
log('Your local version (' + localPackage.version + ') does not match the installed version (' + npmPackage.version + ')\n\n' + | ||
'Please run `npm update` in ./benchmarks to ensure you are benchmarking\n' + | ||
'the latest version of this package.\n'); | ||
process.exit(0); | ||
} | ||
|
||
var assert = require('assert'); | ||
var benchmark = require('benchmark'); | ||
|
||
function sortClasses (str) { | ||
return str.split(' ').sort().join(' '); | ||
} | ||
var runChecks = require('./runChecks'); | ||
var runSuite = require('./runSuite'); | ||
|
||
fixtures.forEach(function (f) { | ||
// sort assertions because dedupe returns results in a different order | ||
assert.equal(sortClasses(local.apply(null, f.args)), sortClasses(f.expected)); | ||
assert.equal(sortClasses(dedupe.apply(null, f.args)), sortClasses(f.expected)); | ||
assert.equal(sortClasses(npm.apply(null, f.args)), sortClasses(f.expected)); | ||
assert.equal(sortClasses(npmDedupe.apply(null, f.args)), sortClasses(f.expected)); | ||
|
||
var suite = new benchmark.Suite(); | ||
|
||
suite.add('local#' + f.description, function () { | ||
local.apply(null, f.args); | ||
}); | ||
|
||
suite.add(' npm#' + f.description, function () { | ||
npm.apply(null, f.args); | ||
}); | ||
|
||
suite.add('local/dedupe#' + f.description, function () { | ||
dedupe.apply(null, f.args); | ||
}); | ||
|
||
suite.add(' npm/dedupe#' + f.description, function () { | ||
npmDedupe.apply(null, f.args); | ||
}); | ||
|
||
// after each cycle | ||
suite.on('cycle', function (event) { | ||
console.log('*', String(event.target)); | ||
}); | ||
|
||
// other handling | ||
suite.on('complete', function () { | ||
console.log('\n> Fastest is' + (' ' + this.filter('fastest').pluck('name').join(' | ')).replace(/\s+/, ' ') + '\n'); | ||
}); | ||
|
||
suite.on('error', function (event) { | ||
throw event.target.error; | ||
}); | ||
|
||
suite.run(); | ||
runChecks(local, npm, dedupe, npmDedupe, f); | ||
runSuite(local, npm, dedupe, npmDedupe, f, log); | ||
}); |
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,15 @@ | ||
var assert = require('assert'); | ||
|
||
function sortClasses (str) { | ||
return str.split(' ').sort().join(' '); | ||
} | ||
|
||
function runChecks (local, npm, dedupe, npmDedupe, fixture) { | ||
// sort assertions because dedupe returns results in a different order | ||
assert.equal(sortClasses(local.apply(null, fixture.args)), sortClasses(fixture.expected)); | ||
assert.equal(sortClasses(dedupe.apply(null, fixture.args)), sortClasses(fixture.expected)); | ||
assert.equal(sortClasses(npm.apply(null, fixture.args)), sortClasses(fixture.expected)); | ||
assert.equal(sortClasses(npmDedupe.apply(null, fixture.args)), sortClasses(fixture.expected)); | ||
} | ||
|
||
module.exports = runChecks; |
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,50 @@ | ||
var fixtures = require('./fixtures'); | ||
var local = require('../'); | ||
var dedupe = require('../dedupe'); | ||
var localPackage = require('../package.json'); | ||
|
||
var npm = require('classnames'); | ||
var npmDedupe = require('classnames/dedupe'); | ||
var npmPackage = require('./node_modules/classnames/package.json'); | ||
|
||
function log (message) { | ||
console.log(message); | ||
var results = document.getElementById('results'); | ||
//noinspection InnerHTMLJS | ||
results.innerHTML += (message + '\n').replace(/\n/g, '<br/>'); | ||
} | ||
|
||
if (localPackage.version !== npmPackage.version) { | ||
log('Your local version (' + localPackage.version + ') does not match the installed version (' + npmPackage.version + ')\n\n' + | ||
'Please run `npm update` in ./benchmarks to ensure you are benchmarking\n' + | ||
'the latest version of this package.\n'); | ||
return; | ||
} | ||
|
||
function iterate (array, iterator, i, callback) { | ||
if (i >= 0 && i < array.length) { | ||
iterator(array[i], i, array); | ||
setTimeout(iterate.bind(null, array, iterator, i + 1, callback), 1); | ||
} else if (callback) { | ||
callback(); | ||
} | ||
} | ||
|
||
function deferredForEach (array, iterator, callback) { | ||
iterate(array, iterator, 0, callback); | ||
} | ||
|
||
var runSuite = require('./runSuite'); | ||
|
||
window.onload = function () { | ||
//noinspection PlatformDetectionJS | ||
log(navigator.userAgent); | ||
setTimeout(function () { | ||
deferredForEach(fixtures, function (f) { | ||
runSuite(local, npm, dedupe, npmDedupe, f, log); | ||
}, function () { | ||
log('Finished'); | ||
document.getElementById('loader').style.display = 'none'; | ||
}); | ||
}, 100); | ||
}; |
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,40 @@ | ||
var benchmark = require('benchmark'); | ||
|
||
function runSuite (local, npm, dedupe, npmDedupe, fixture, log) { | ||
var suite = new benchmark.Suite(); | ||
|
||
suite.add('local#' + fixture.description, function () { | ||
local.apply(null, fixture.args); | ||
}); | ||
|
||
suite.add(' npm#' + fixture.description, function () { | ||
npm.apply(null, fixture.args); | ||
}); | ||
|
||
suite.add('local/dedupe#' + fixture.description, function () { | ||
dedupe.apply(null, fixture.args); | ||
}); | ||
|
||
suite.add(' npm/dedupe#' + fixture.description, function () { | ||
npmDedupe.apply(null, fixture.args); | ||
}); | ||
|
||
// after each cycle | ||
suite.on('cycle', function (event) { | ||
log('* ' + String(event.target)); | ||
}); | ||
|
||
// other handling | ||
suite.on('complete', function () { | ||
log('\n> Fastest is' + (' ' + this.filter('fastest').pluck('name').join(' | ')).replace(/\s+/, ' ') + '\n'); | ||
}); | ||
|
||
suite.on('error', function (event) { | ||
log(event.target.error.message); | ||
throw event.target.error; | ||
}); | ||
|
||
suite.run(); | ||
} | ||
|
||
module.exports = runSuite; |
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