Created
December 26, 2011 15:35
-
-
Save zenlor/1521429 to your computer and use it in GitHub Desktop.
Revisions
-
zenlor revised this gist
Jul 3, 2012 . 5 changed files with 35 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -81,17 +81,5 @@ Step( }); } , function () { process.exit(); } ); This file contains hidden or 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 @@ -1,5 +0,0 @@ This file contains hidden or 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,15 @@ in my node_modules folder ... walk() Finished in: 30 ms exec('find ...') Finished in: 14 ms spawn('find ...') Finished in: 6 ms using node 0.8.1 walk() Finished in: 17 ms exec('find ...') Finished in: 8 ms spawn('find ...') Finished in: 5 ms results may vary This file contains hidden or 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,19 @@ { "name": "gist-1521429", "version": "0.0.0", "main": "Benchmark-ish.js", "dependencies": {}, "devDependencies": { "colors": "~0.6.0-1", "express": "~2.5.11", "step": "~0.0.5" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git://gist.github.com/1521429.git" }, "license": "BSD" } This file contains hidden or 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 @@ -1,10 +0,0 @@ -
zenlor revised this gist
Dec 26, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -60,7 +60,7 @@ Step( var self = this; start = Date.now(); cp.exec('find ./node_modules -type f', function(error, stdout, stderr) { if (error) throw error; console.log("exec('find ...') Finished in: %d ms".red, (Date.now()) - start); ex = stdout; @@ -71,7 +71,7 @@ Step( var self = this; start = Date.now(); var cmd = cp.spawn('find', ['./node_modules', '-type', 'f']); cmd.stdout.on('data', function (data) { sp += data; }); @@ -90,8 +90,8 @@ Step( console.log('EX::::'.green) console.log('\n\nSP::::'.magenta) console.log(sp) console.log('SP::::'.green) process.exit(); } ); -
zenlor revised this gist
Dec 26, 2011 . No changes.There are no files selected for viewing
-
zenlor revised this gist
Dec 26, 2011 . 3 changed files with 112 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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,97 @@ var fs = require('fs') , path = require("path") , cp = require('child_process') , Step = require('step') , colors = require('colors') , start = Date.now(); walk = (function() { var counter = 0; var walk = function(dirname, callback, finished) { counter += 1; fs.readdir(dirname, function(err, relnames) { if(err) { finished(err); return; } relnames.forEach(function(relname, index, relnames) { var name = path.join(dirname, relname); counter += 1; fs.lstat(name, function(err, stat) { if(err) { finished(err); return; } if(stat.isDirectory()) { walk(name, callback, finished); } else { callback(name); } counter -= 1; if(index === relnames.length - 1) counter -= 1; if(counter === 0) { finished(null); } }); }); }); }; return walk; })(); var js = ex = sp = ''; Step( function () { var self = this; walk( "./node_modules" , function(data) { js += (data + '\n'); } , function(err) { if(err) throw err; console.log("walk() Finished in: %d ms".red, (Date.now()) - start); return self(); } ) } , function () { var self = this; start = Date.now(); cp.exec('find ./node_modules', function(error, stdout, stderr) { if (error) throw error; console.log("exec('find ...') Finished in: %d ms".red, (Date.now()) - start); ex = stdout; self(); }); } , function () { var self = this; start = Date.now(); var cmd = cp.spawn('find', ['./node_modules']); cmd.stdout.on('data', function (data) { sp += data; }); cmd.on('exit', function () { console.log("spawn('find ...') Finished in: %d ms".red, (Date.now()) - start); self(); }); } , function () { console.log('\n\nJS::::'.magenta) console.log(js) console.log('JS::::'.green) console.log('\n\nEX::::'.magenta) console.log(ex) console.log('EX::::'.green) console.log('\n\nSP::::'.magenta) console.log(js) console.log('SP::::'.green) process.exit(); } ); This file contains hidden or 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,5 @@ in my node_modules folder ... walk() Finished in: 30 ms exec('find ...') Finished in: 14 ms spawn('find ...') Finished in: 6 ms This file contains hidden or 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,10 @@ require("./walk").walk( "/path/to/a/directory", function(file) { console.log(file); }, function(err) { if(err) throw err; console.log("Finished."); } ); -
stygstra revised this gist
Aug 9, 2010 . 3 changed files with 46 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -1,44 +0,0 @@ This file contains hidden or 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,10 @@ require("./walk").walk( "/path/to/a/directory", function(file) { console.log(file); }, function(err) { if(err) throw err; console.log("Finished."); } ); This file contains hidden or 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,36 @@ var fs = require("fs"); var path = require("path"); exports.walk = (function() { var counter = 0; var walk = function(dirname, callback, finished) { counter += 1; fs.readdir(dirname, function(err, relnames) { if(err) { finished(err); return; } relnames.forEach(function(relname, index, relnames) { var name = path.join(dirname, relname); counter += 1; fs.stat(name, function(err, stat) { if(err) { finished(err); return; } if(stat.isDirectory()) { exports.walk(name, callback, finished); } else { callback(name); } counter -= 1; if(index === relnames.length - 1) counter -= 1; if(counter === 0) { finished(null); } }); }); }); }; return walk; })(); -
inimino revised this gist
Feb 3, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -20,7 +20,7 @@ var listdir = function (pathname) { var walk = function (pathname, callback) { var counter=1; var promise = new process.Promise(); go(pathname); return promise; function go(pathname){ listdir(pathname).addCallback(function(files) { @@ -30,7 +30,7 @@ var walk = function (pathname, callback) { posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { counter++; go(abspath); } else { callback(abspath); } -
inimino revised this gist
Feb 3, 2010 . 1 changed file with 20 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -17,29 +17,28 @@ var listdir = function (pathname) { return p; } var walk = function (pathname, callback) { var counter=1; var promise = new process.Promise(); go(); return promise; function go(pathname){ listdir(pathname).addCallback(function(files) { counter--; files.forEach(function(f) { var abspath = path.join(pathname, f); posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { counter++; walk(abspath, callback); } else { callback(abspath); } }); }); if(!counter) promise.emitSuccess(); }); } } walk('/home/node', function() {}); -
Tim-Smart revised this gist
Feb 3, 2010 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -16,14 +16,14 @@ var listdir = function (pathname) { }); return p; } var counter = 0; var walk = function (pathname, callback) { counter++; listdir(pathname).addCallback(function(files) { var finished = true; files.forEach(function(f) { var abspath = path.join(pathname, f); posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { finished = false; @@ -33,12 +33,13 @@ var walk = function (pathname, callback) { } }); }); counter--; if (true === finished && 0 >= counter) callback(null); }); } walk('/home/node', function() { if (null === file) finished(); }); -
Tim-Smart revised this gist
Feb 3, 2010 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -27,7 +27,7 @@ var walk = function (pathname, callback) { posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { finished = false; walk(abspath, callback); } else { callback(abspath); } @@ -39,7 +39,6 @@ var walk = function (pathname, callback) { }); } walk('/home/node', function() { sys.puts(sys.inspect(arguments)); }); -
Tim-Smart revised this gist
Feb 3, 2010 . 1 changed file with 21 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -3,31 +3,43 @@ var http = require('http'), path = require('path'), posix = require('posix'), events = require('events'); var listdir = function (pathname) { var p = new events.Promise(); var ls = process.createChildProcess("ls", [pathname]); ls.addListener("output", function (data) { if (data) { var files = []; data.split('\n').forEach(function(f) {if (f){files.push(f)}}); p.emitSuccess(files) } }); return p; } var walk = function (pathname, callback) { listdir(pathname).addCallback(function(files) { var finished = true; files.forEach(function(f) { var abspath = path.join(pathname, f); posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { finished = false; dirs.push(abspath); } else { callback(abspath); } }); }); if (true === finished) callback(null); }); } walk('/home/node', function(file) { if (null === file) finished(); }); -
mikeal created this gist
Feb 3, 2010 .There are no files selected for viewing
This file contains hidden or 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,33 @@ var http = require('http'), sys = require('sys'), path = require('path'), posix = require('posix'), events = require('events'); var listdir = function (pathname) { var p = new events.Promise(); var ls = process.createChildProcess("ls", [pathname]); ls.addListener("output", function (data) { if (data) { var files = []; data.split('\n').forEach(function(f) {if (f){files.push(f)}}); p.emitSuccess(files) } }); return p; } var walk = function (pathname, callback) { listdir(pathname).addCallback(function(files) { files.forEach(function(f) { var abspath = path.join(pathname, f) posix.stat(abspath).addCallback(function(stat) { if (stat.isDirectory()) { walk(abspath, callback); } else { callback(abspath); } }).wait(); }) }).wait(); }