(title, config)
| 87 | ]); |
| 88 | |
| 89 | function bench (title, config) { |
| 90 | return function (next) { |
| 91 | var suite = new Benchmark.Suite(); |
| 92 | var keys = Object.keys(config), |
| 93 | total = keys.length, |
| 94 | key, i; |
| 95 | |
| 96 | for (i = 0; i < total; i++) { |
| 97 | key = keys[i]; |
| 98 | suite.add(key, config[key]); |
| 99 | } |
| 100 | |
| 101 | suite.on('start', function () { |
| 102 | console.log(' ' + title); |
| 103 | }); |
| 104 | suite.on('cycle', function (event) { |
| 105 | console.log(" \033[0;32m\✓\033[0m \033[0;37m " + event.target + "\033[0m"); |
| 106 | }); |
| 107 | suite.on('complete', function () { |
| 108 | var slowest = this.filter('slowest')[0], |
| 109 | baselineSuite = this.shift(), |
| 110 | fastJSSuite = this.shift(); |
| 111 | |
| 112 | // In most benchmarks, the first entry is the native implementation and |
| 113 | // the second entry is the fast.js one. However, not all benchmarks have |
| 114 | // a native baseline implementation (e.g. there is none for "clone"). |
| 115 | // In such a case, use the slowest benchmark result as a baseline. |
| 116 | if (fastJSSuite.name.indexOf('fast') != 0) { |
| 117 | fastJSSuite = baselineSuite; |
| 118 | baselineSuite = slowest; |
| 119 | } |
| 120 | |
| 121 | var diff = fastJSSuite.hz - baselineSuite.hz, |
| 122 | percentage = ((diff / baselineSuite.hz) * 100).toFixed(2), |
| 123 | relation = 'faster'; |
| 124 | |
| 125 | if (percentage < 0) { |
| 126 | relation = 'slower'; |
| 127 | percentage *= -1; |
| 128 | } |
| 129 | |
| 130 | console.log('\n \033[0;37mResult:\033[0m fast.js \033[0;37mis\033[0m ' + percentage + '% ' + relation + ' \033[0;37mthan\033[0m ' + baselineSuite.name + '.\n'); |
| 131 | next(); |
| 132 | }); |
| 133 | suite.run({ |
| 134 | async: true |
| 135 | }); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | function run (benchmarks) { |
no outgoing calls
no test coverage detected
searching dependent graphs…