Return to Snippet

Revision: 26537
at April 30, 2010 08:20 by irrevokable


Initial Code
// IRR Bencher
/**
  * @param f function to test
  * @param i iterations count (default is 10000)
  * @param n number of tests (default is 10)
  * @param a args
  * @param l label -- not implemented yet
 */
function Bencher(f, i, n, a, l){
    i = i||10000;
    n = n||10;
    l = l||'#test#';
    var e=-1, k=-1, t=0;
    var ar=[];
	
    while(++e<n){
        k = -1;
        t = getTimer();
        while(++k<i){
            a ? f.apply(null,a): f();
        }
        ar[e] = getTimer() - t;
    }
    return avg(ar)+' ms ';
}

//check DOM Existance
if(document){
	var trace = function(v){ document.writeln(v+'<br>')};
	var getTimer = function(){
       var _time = new Date();
       return parseFloat(_time.valueOf());
	}
}
// count average
function avg(a){
	var s = 0;
	for(var i in a)s+=a[i];
	return s/a.length;
}


// SIMPLE TESTS
var bms =
[
Bencher(function(){var a=[];}),
Bencher(function(){var a={};}),
Bencher(function(){var a=new Array;}),
Bencher(function(){var a=new Object;}),
Bencher(function(){var a=Math.random();})
];
trace(bms);



// HTML CODE 
/*
<html>
<head>
<script src="Bencher-jsas.js"></script>
</head>
<body>
</body>
</html>
*/

Initial URL

                                

Initial Description
Just a simple benchmark utility, working both in AS2 & JS.

Initial Title
JS/AS2 simple Benchmark Tool

Initial Tags
javascript

Initial Language
JavaScript