Skip to content

Commit

Permalink
update benchmark script
Browse files Browse the repository at this point in the history
* use ES2015 code
* add object-key version
  • Loading branch information
shinnn committed May 25, 2015
1 parent 9ff42f3 commit c14c242
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
20 changes: 20 additions & 0 deletions benchmark/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var fileType = require('file-type');

var types = {
png: true,
jpg: true,
tif: true,
webp: true
}

module.exports = function isCwebpReadable(buf) {
var type = fileType(buf);

if (!type) {
return false;
}

return !!types[type.ext];
};
21 changes: 13 additions & 8 deletions benchmark/runner.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
/* globals set, suite, bench */
'use strict';

var main = require('..');
var indexOf = require('./index-of.js');
var regex = require('./regex.js');
const main = require('..');
const indexOf = require('./index-of.js');
const keys = require('./keys.js');
const regex = require('./regex.js');

var fixture = new Buffer(100);
const fixture = new Buffer(100);

suite('Detect file type', function() {
suite('Detect file type', () => {
set('iterations', 30000);

bench('logical OR (current version)', function() {
bench('logical OR (current version)', () => {
main(fixture);
});

bench('array.indexOf', function() {
bench('array.indexOf', () => {
indexOf(fixture);
});

bench('regular expression', function() {
bench('keys', () => {
regex(fixture);
});

bench('regular expression', () => {
regex(fixture);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repository": "shinnn/is-cwebp-readable",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"bench": "matcha benchmark/runner.js",
"bench": "node --harmony_arrow_functions node_modules/.bin/_matcha benchmark/runner.js",
"pretest": "eslint --config node_modules/@shinnn/eslintrc-node/rc.json index.js benchmark test.js",
"test": "node --harmony_arrow_functions test.js | tap-spec",
"coverage": "node --harmony_arrow_functions node_modules/.bin/istanbul cover test.js",
Expand Down

0 comments on commit c14c242

Please sign in to comment.