Skip to content

Commit

Permalink
Add script and cmd to test hash/checksum performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zeveshe committed Apr 24, 2017
1 parent f9e5c69 commit 7f60e0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"node": ">=0.10.0"
},
"scripts": {
"beautify": "esbeautifier 'cache.js' 'test/**/*.js'",
"beautify": "esbeautifier 'cache.js' 'test/**/*.js' 'perf.js'",
"beautify-check": "npm run beautify -- -k",
"eslint": "eslinter 'cache.js' 'specs/**/*.js'",
"eslint": "eslinter 'cache.js' 'specs/**/*.js' 'perf.js'",
"lint": "npm run beautify && npm run eslint",
"verify": "npm run beautify-check && npm run eslint",
"install-hooks": "prepush install && changelogx install-hook && precommit install",
Expand All @@ -30,6 +30,7 @@
"bump-minor": "npm run pre-v && npm version minor -m 'BLD: Release v%s' && npm run post-v",
"bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v",
"test": "npm run verify --silent && mocha -R spec test/specs",
"perf": "node perf.js",
"cover": "istanbul cover test/runner.js html text-summary",
"watch": "watch-run -i -p 'test/specs/**/*.js' istanbul cover test/runner.js html text-summary"
},
Expand Down
25 changes: 25 additions & 0 deletions perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var fs = require( 'fs' );
var path = require( 'path' );
var fileEntryCache = require( './cache.js' );


var TEST_FILE_SIZE = 32;
var TEST_FILE_PATH = path.resolve( __dirname, '.perf.file' );
var RUNS = 10000;
var LOOPS = 5;
var TIMER_NAME = 'cache.hasFileChanged (' + TEST_FILE_SIZE + ' KB file, ' + RUNS + ' runs)';


for (var i = 0; i < LOOPS; i++) {
var cache = fileEntryCache.createFromFile( '.perfcache' );
fs.writeFileSync( TEST_FILE_PATH, new Buffer( 1024 * TEST_FILE_SIZE ) );

console.time( TIMER_NAME );
for (var j = 0; j < RUNS; j++) {
cache.hasFileChanged( TEST_FILE_PATH );
}
console.timeEnd( TIMER_NAME );

cache.deleteCacheFile();
fs.unlinkSync( TEST_FILE_PATH );
}

0 comments on commit 7f60e0a

Please sign in to comment.