Created
October 5, 2011 15:31
-
-
Save stash/1264732 to your computer and use it in GitHub Desktop.
Logging with runtime level selection in node.js
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 characters
| var N = process.argv[2] || 1000000; | |
| function log () { | |
| console.log.apply(console,arguments); | |
| } | |
| for (var i=0; i<N; i++) { | |
| log("this is message"+i); | |
| } | |
| // didn't run to completion, stopped at ~5m18s | |
| // real 5m18.449s | |
| // user 5m15.645s | |
| // sys 0m5.304s |
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 characters
| var LOG = false; | |
| var N = process.argv[2] || 1000000; | |
| function log () { | |
| if (!LOG) return; | |
| console.log.apply(console,arguments); | |
| } | |
| for (var i=0; i<N; i++) { | |
| log("this is message"+i); | |
| } | |
| // real 0m0.331s | |
| // user 0m0.294s | |
| // sys 0m0.028s |
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 characters
| var LOG = false; | |
| var N = process.argv[2] || 1000000; | |
| function log () { | |
| console.log.apply(console,arguments); | |
| } | |
| for (var i=0; i<N; i++) { | |
| LOG && log("this is message"+i); | |
| } | |
| // real 0m0.117s | |
| // user 0m0.094s | |
| // sys 0m0.016s |
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 characters
| var LOG = false; | |
| var N = process.argv[2] || 1000000; | |
| function log () { | |
| console.log.apply(console,arguments); | |
| } | |
| if (!LOG) log = function(){}; | |
| for (var i=0; i<N; i++) { | |
| log("this is message"+i); | |
| } | |
| // real 0m0.311s | |
| // user 0m0.272s | |
| // sys 0m0.027s |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ran with
time (node file.js >/dev/null 2>&1), took the worst times out of 4 consecutive runs.