1 |
// Benchmarking Class |
2 |
Class("Joose.Benchmark", { |
3 |
has: { |
4 |
iterations: {}, |
5 |
func: {}, |
6 |
desc: {} |
7 |
}, |
8 |
methods: { |
9 |
initialize: function (iterations, desc, func) { |
10 |
this.iterations = iterations; |
11 |
this.func = func; |
12 |
this.desc = desc; |
13 |
}, |
14 |
run: function () { |
15 |
var func = this.func; |
16 |
var iterations = this.iterations; |
17 |
var start = new Date().getTime(); |
18 |
for(var i = 0; i < iterations; i++) { |
19 |
func(); |
20 |
} |
21 |
var end = new Date().getTime(); |
22 |
return (end - start) / 1000; |
23 |
}, |
24 |
|
25 |
report: function () { |
26 |
var result = this.run() |
27 |
var perSec = Math.round(this.iterations / result); |
28 |
return ""+this.desc + " over "+this.iterations+" iterations took "+result+" seconds ("+perSec+" iterations per second)"; |
29 |
} |
30 |
} |
31 |
}) |