Permalink
Browse files

Proper oom calculation

  • Loading branch information...
1 parent 4022216 commit d14aa704f119f2f1cb3bd6e22f86f9c658bc7c6a @isaacs committed Sep 29, 2010
Showing with 7 additions and 7 deletions.
  1. +7 −7 lib/bench.js
View
@@ -60,8 +60,6 @@ function run (fn, time, countPerLap, cb) {
lap();
};
runner();
-
- return p;
};
function compare (set, compareCount, time, countPerLap, cb) {
@@ -168,12 +166,14 @@ function pct (num1, num2) {
function times (num1, num2) {
return Math.round((Math.max(num1, num2)/Math.min(num1, num2)) * 100) / 100;
}
+function logX (n, x) {
+ return Math.log(n)/Math.log(x)
+}
function oom (num1, num2) {
- var ratio = Math.max(num1, num2)/Math.min(num1, num2),
- oom = 0;
- // poor man's logarithm
- while ( (ratio/=10) > 0.9 ) oom++;
- return oom;
+ var l1 = logX(num1, 10)
+ , l2 = logX(num2, 10)
+ , diff = Math.abs( l1 - l2 )
+ return Math.round(diff * 100) / 100
}
function avg (nums) {
var sum = 0;

0 comments on commit d14aa70

Please sign in to comment.