Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance #109

Merged
merged 2 commits into from Oct 15, 2017
Merged

Improve performance #109

merged 2 commits into from Oct 15, 2017

Conversation

magicode
Copy link
Contributor

fix PR #100
Improve performance up 30 times
this benchmark

 
const fs = require('fs');
const filetype = require('.');

var file = fs.readFileSync(__dirname + "/fixture/fixture.png");

var time = 3000;
var starttime = Date.now();
var endtime = starttime + time;
var count = 0;
for(;Date.now()<endtime;count++){
    filetype(file);
}

console.log("%d ops/s" ,~~(count/((Date.now()-starttime)/1000)));

@mifi
Copy link
Sponsor Contributor

mifi commented Oct 15, 2017

Thanks @magicode. Good idea to check the type, but there are 2 issues:

  1. Buffer is already instanceof Uint8array, so no need to check for Buffer
  2. Buffer might not exist in a browser environment so that check might give a ReferenceError

@mifi mifi merged commit e55a655 into sindresorhus:master Oct 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants