Skip to content

Commit

Permalink
benchmark script
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Dec 6, 2018
1 parent f6557d1 commit a1d884c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
44 changes: 30 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"benchmark": "^2.1.4",
"chalk": "1.1.3",
"eslint": "^5.9.0",
"mime-db": "^1.37.0",
Expand All @@ -27,6 +28,7 @@
"scripts": {
"prepare": "node src/build.js && runmd --output README.md src/README_js.md",
"release": "standard-version",
"benchmark": "node src/benchmark.js",
"md": "runmd --watch --output README.md src/README_js.md",
"test": "mocha src/test.js"
},
Expand Down
26 changes: 26 additions & 0 deletions src/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Benchmark = require('benchmark');
const mime = require('..');
const mimeLite = require('../lite');

const suite = new Benchmark.Suite();

const extensions = Object.keys(mime._types);
let idx = 0;

suite
.add('mime.getType',
function() {
mime.getType(extensions[idx++]);
if (idx >= extensions.length) idx = 0;
}
)
.add('mimeLite.getType',
function() {
mimeLite.getType(extensions[idx++]);
if (idx >= extensions.length) idx = 0;
}
)
.on('cycle', function(event) {
console.log(String(event.target));
})
.run();

0 comments on commit a1d884c

Please sign in to comment.