Mercurial > hg > nodescore
annotate node_modules/socket.io/benchmarks/runner.js @ 75:3a2845e3156e
added martin tweaks
author | Rob Canning <rc@kiben.net> |
---|---|
date | Tue, 01 Jul 2014 08:51:53 +0000 |
parents | 333afcfd3f3a |
children |
rev | line source |
---|---|
rc-web@69 | 1 /** |
rc-web@69 | 2 * Benchmark runner dependencies |
rc-web@69 | 3 */ |
rc-web@69 | 4 |
rc-web@69 | 5 var colors = require('colors') |
rc-web@69 | 6 , path = require('path'); |
rc-web@69 | 7 |
rc-web@69 | 8 /** |
rc-web@69 | 9 * Find all the benchmarks |
rc-web@69 | 10 */ |
rc-web@69 | 11 |
rc-web@69 | 12 var benchmarks_files = process.env.BENCHMARKS.split(' ') |
rc-web@69 | 13 , all = [].concat(benchmarks_files) |
rc-web@69 | 14 , first = all.shift() |
rc-web@69 | 15 , benchmarks = {}; |
rc-web@69 | 16 |
rc-web@69 | 17 // find the benchmarks and load them all in our obj |
rc-web@69 | 18 benchmarks_files.forEach(function (file) { |
rc-web@69 | 19 benchmarks[file] = require(path.join(__dirname, '..', file)); |
rc-web@69 | 20 }); |
rc-web@69 | 21 |
rc-web@69 | 22 // setup the complete listeners |
rc-web@69 | 23 benchmarks_files.forEach(function (file) { |
rc-web@69 | 24 var benchmark = benchmarks[file] |
rc-web@69 | 25 , next_file = all.shift() |
rc-web@69 | 26 , next = benchmarks[next_file]; |
rc-web@69 | 27 |
rc-web@69 | 28 /** |
rc-web@69 | 29 * Generate a oncomplete function for the tests, either we are done or we |
rc-web@69 | 30 * have more benchmarks to process. |
rc-web@69 | 31 */ |
rc-web@69 | 32 |
rc-web@69 | 33 function complete () { |
rc-web@69 | 34 if (!next) { |
rc-web@69 | 35 console.log( |
rc-web@69 | 36 '\n\nBenchmark completed in'.grey |
rc-web@69 | 37 , (Date.now() - start).toString().green + ' ms'.grey |
rc-web@69 | 38 ); |
rc-web@69 | 39 } else { |
rc-web@69 | 40 console.log('\nStarting benchmark '.grey + next_file.yellow); |
rc-web@69 | 41 next.run(); |
rc-web@69 | 42 } |
rc-web@69 | 43 } |
rc-web@69 | 44 |
rc-web@69 | 45 // attach the listener |
rc-web@69 | 46 benchmark.on('complete', complete); |
rc-web@69 | 47 }); |
rc-web@69 | 48 |
rc-web@69 | 49 /** |
rc-web@69 | 50 * Start the benchmark |
rc-web@69 | 51 */ |
rc-web@69 | 52 |
rc-web@69 | 53 var start = Date.now(); |
rc-web@69 | 54 console.log('Starting benchmark '.grey + first.yellow); |
rc-web@69 | 55 benchmarks[first].run(); |