Created
April 11, 2012 20:01
Revisions
-
bjouhier revised this gist
Apr 11, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ function bench(cb) { cb(null, total); } else { load(__dirname + '/benchCallbacks.js', function(err, data) { if (err) return cb(err); total += data.length; loop(i + 1); }) -
bjouhier revised this gist
Apr 11, 2012 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function bench(cb) { if (i === count) { cb(null, total); } else { load(__dirname + '/benchCallbacks.js', function(err, data) { if (err) cb(err); total += data.length; loop(i + 1); This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ var count = 1000000; function bench(_) { var total = 0; for (var i = 0; i < count; i++) { var res = load(__dirname + '/benchCallbacks.js', _); total += res.length; } return total; -
bjouhier created this gist
Apr 11, 2012 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ "use strict"; var fs = require('fs'); var cache = {}, hit = 0, missed = 0; function load(name, cb) { var res = cache[name]; if (res) { process.nextTick(function() { hit++; cb(null, res); }); } else { fs.readFile(name, function(err, data) { missed++; cb(null, cache[name] = data); }); } } var count = 1000000; function bench(cb) { var total = 0; function loop(i) { if (i === count) { cb(null, total); } else { load(__dirname + '/benchCb.js', function(err, data) { if (err) cb(err); total += data.length; loop(i + 1); }) } } loop(0); } var t0 = Date.now(); bench(function(err, result) { if (err) throw err; console.log('hit=' + hit + ', missed=' + missed + ', result=' + result); console.log('elapsed: ' + (Date.now() - t0)); }); This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ "use strict"; var fs = require('fs'); var cache = {}, hit = 0, missed = 0; function load(name, _) { var res = cache[name]; if (res) { hit++; return res; } else { missed++; return cache[name] = fs.readFile(name, _); } } var count = 1000000; function bench(_) { var total = 0; for (var i = 0; i < count; i++) { var res = load(__dirname + '/benchCb.js', _); total += res.length; } return total; } var t0 = Date.now(); var result = bench(_); console.log('hit=' + hit + ', missed=' + missed + ', result=' + result); console.log('elapsed: ' + (Date.now() - t0));