diff options
author | isaacs <i@izs.me> | 2013-02-13 14:16:11 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-02-19 17:16:55 -0800 |
commit | 06fbcca6bb14093ca3bed6bd558d900ad8cead62 (patch) | |
tree | 7473186a663d35f7a250704a1669f85f31b506a0 /benchmark | |
parent | ef08f0fbb19ba1e45721b759f37efd6574c400a3 (diff) | |
download | nodejs-06fbcca6bb14093ca3bed6bd558d900ad8cead62.tar.gz nodejs-06fbcca6bb14093ca3bed6bd558d900ad8cead62.tar.bz2 nodejs-06fbcca6bb14093ca3bed6bd558d900ad8cead62.zip |
bench: Remove _bench_timer (no loner used)
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/_bench_timer.js | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/benchmark/_bench_timer.js b/benchmark/_bench_timer.js deleted file mode 100644 index 43460945f..000000000 --- a/benchmark/_bench_timer.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This is a simple addition to allow for higher resolution timers. - * It can be used to track time for both synchronous or asynchronous - * calls. For synchronous calls pass a callback function like so: - * - * var timer = require('./_bench_timer'); - * - * timer('myTest', function() { - * for (var i = 0; i < 1e6; i++) - * // ... run something here - * } - * }); - * - * For asynchronous timers just pass the name. Then run it again with - * the same name to finish it: - * - * timer('checkAsync'); - * setTimeout(function() { - * timer('checkAsync'); - * }, 300); - * - * When this happens all currently queued benchmarks will be paused - * until the asynchronous benchmark has completed. - * - * If the benchmark has been run with --expose_gc then the garbage - * collector will be run between each test. - * - * The setTimeout delay can also be changed by passing a value to - * timer.delay. - */ - - -var store = {}; -var order = []; -var maxLength = 0; -var processing = false; -var asyncQueue = 0; -var GCd = typeof gc !== 'function' ? false : true; - -function timer(name, fn) { - if (maxLength < name.length) - maxLength = name.length; - if (!fn) { - processing = false; - if (!store[name]) { - asyncQueue++; - store[name] = process.hrtime(); - return; - } - displayTime(name, process.hrtime(store[name])); - asyncQueue--; - } else { - store[name] = fn; - order.push(name); - } - if (!processing && asyncQueue <= 0) { - processing = true; - setTimeout(run, timer.delay); - } -} - -timer.delay = 100; - -function run() { - if (asyncQueue > 0 || order.length <= 0) - return; - if (GCd) gc(); - setTimeout(function() { - var name = order.shift(); - var fn = store[name]; - var ini = process.hrtime(); - fn(); - ini = process.hrtime(ini); - displayTime(name, ini); - run(); - }, timer.delay); -} - -function displayTime(name, ini) { - name += ': '; - while (name.length < maxLength + 2) - name += ' '; - console.log(name + '%s \u00b5s', - (~~((ini[0] * 1e6) + (ini[1] / 1e3))) - .toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); -} - -module.exports = timer; |