diff --git a/.travis.yml b/.travis.yml index 4b960f2..8ca079e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ dist: precise before_install: # Skip updating shrinkwrap / lock - "npm config set shrinkwrap false" + # Remove all non-test dependencies + - "npm rm --save-dev beautify-benchmark benchmark" # Setup Node.js version-specific dependencies - "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul" - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" diff --git a/benchmark/etag.js b/benchmark/etag.js new file mode 100644 index 0000000..dc53ec4 --- /dev/null +++ b/benchmark/etag.js @@ -0,0 +1,47 @@ + +/** + * Module dependencies. + */ + +var benchmark = require('benchmark') +var benchmarks = require('beautify-benchmark') + +/** + * Globals for benchmark.js + */ + +global.fresh = require('..') + +var suite = new benchmark.Suite() + +suite.add({ + name: 'star', + minSamples: 100, + fn: 'var val = fresh({ \'if-none-match\': \'*\' }, { etag: \'"foo"\' })' +}) + +suite.add({ + name: 'single etag', + minSamples: 100, + fn: 'var val = fresh({ \'if-none-match\': \'"foo"\' }, { etag: \'"foo"\' })' +}) + +suite.add({ + name: 'several etags', + minSamples: 100, + fn: 'var val = fresh({ \'if-none-match\': \'"foo", "bar", "fizz", "buzz"\' }, { etag: \'"buzz"\' })' +}) + +suite.on('start', function onCycle (event) { + process.stdout.write(' etag\n\n') +}) + +suite.on('cycle', function onCycle (event) { + benchmarks.add(event.target) +}) + +suite.on('complete', function onComplete () { + benchmarks.log() +}) + +suite.run({async: false}) diff --git a/benchmark/index.js b/benchmark/index.js new file mode 100644 index 0000000..8a39f3a --- /dev/null +++ b/benchmark/index.js @@ -0,0 +1,34 @@ +var fs = require('fs') +var path = require('path') +var spawn = require('child_process').spawn + +var exe = process.argv[0] +var cwd = process.cwd() + +for (var dep in process.versions) { + console.log(' %s@%s', dep, process.versions[dep]) +} + +console.log('') + +runScripts(fs.readdirSync(__dirname)) + +function runScripts (fileNames) { + var fileName = fileNames.shift() + + if (!fileName) return + if (!/\.js$/i.test(fileName)) return runScripts(fileNames) + if (fileName.toLowerCase() === 'index.js') return runScripts(fileNames) + + var fullPath = path.join(__dirname, fileName) + + console.log('> %s %s', exe, path.relative(cwd, fullPath)) + + var proc = spawn(exe, [fullPath], { + 'stdio': 'inherit' + }) + + proc.on('exit', function () { + runScripts(fileNames) + }) +} diff --git a/benchmark/modified.js b/benchmark/modified.js new file mode 100644 index 0000000..8d99eb0 --- /dev/null +++ b/benchmark/modified.js @@ -0,0 +1,41 @@ + +/** + * Module dependencies. + */ + +var benchmark = require('benchmark') +var benchmarks = require('beautify-benchmark') + +/** + * Globals for benchmark.js + */ + +global.fresh = require('..') + +var suite = new benchmark.Suite() + +suite.add({ + name: 'not modified', + minSamples: 100, + fn: 'var val = fresh({ \'if-modified-since\': \'Fri, 01 Jan 2010 00:00:00 GMT\' }, { \'last-modified\': \'Sat, 01 Jan 2000 00:00:00 GMT\' })' +}) + +suite.add({ + name: 'modified', + minSamples: 100, + fn: 'var val = fresh({ \'if-modified-since\': \'Mon, 01 Jan 1990 00:00:00 GMT\' }, { \'last-modified\': \'Sat, 01 Jan 2000 00:00:00 GMT\' })' +}) + +suite.on('start', function onCycle (event) { + process.stdout.write(' modified\n\n') +}) + +suite.on('cycle', function onCycle (event) { + benchmarks.add(event.target) +}) + +suite.on('complete', function onComplete () { + benchmarks.log() +}) + +suite.run({async: false}) diff --git a/package.json b/package.json index e70c04e..7c1e4f4 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ ], "repository": "jshttp/fresh", "devDependencies": { + "beautify-benchmark": "0.2.4", + "benchmark": "2.1.4", "eslint": "3.19.0", "eslint-config-standard": "10.2.1", "eslint-plugin-import": "2.7.0", @@ -35,6 +37,7 @@ "node": ">= 0.6" }, "scripts": { + "bench": "node benchmark/index.js", "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",