/****************************
 * jQuery Benchmark Plugin
 * https://github.com/kilhage/jquery-benchmark
 *
 * MIT Licensed
 * @author Emil Kilhage
 * Version: 0.8.0
 * Last updated: 2010-11-13 17:37:56
 */
(function($){function Benchmarker(v){if(!(this instanceof Benchmarker)){return new Benchmarker(v)}this.reset();if(!v){this.start()}}var B=$.benchmark=Benchmarker,error_preg=/(\{error\}\:)/,error_messages={callback:" Callback didn't return a value!"},enabled=true,use_console=true,bufferd_output="",name="jQuery.benchmark :: ",output=function(m){if(!enabled){return m}m=(typeof m==="string")?name+m:"";if(error_preg.test(m)){throw name+((m.split(error_preg))[2])}bufferd_output+=m+"<br>";if(use_console){console.log(m)}else{alert(m)}return m},_s="_start",_e="_end",DF="Default",curTest=DF,now=function(){return(new Date()).getTime()};B.prototype={_result:0,start:function(){this.mark("start");return this},end:function(o){this.mark("end","start",(o==null?true:o));return this},mark:function(name,start,o){this.marks[name]=now();if(start){this.elapsedTime(start,name,o)}return this},elapsedTime:function(m1,m2,o){var time=this._result=this.marks[m2]-this.marks[m1];if(o){output(typeof o==="function"?(o(time,m1,m2)||"{error}:elapsedTime->>"+E.callback):"start("+m1+")->> end('"+m2+"') :: Runtime->> "+time+" ms"+(typeof o==="string"?o:""))}return this},result:function(){return this._result},reset:function(){this.marks={}}};$.extend(B,{test:function(a){var o=typeof a==="object"?1:0,args=o===1?a:[],d=B(),g=args.length,i=args[g]=0,c=arguments[0+o],l=arguments[1+o]||1000;for(;i<=l;args[g]=++i){c.apply(window,args)}return d.end(function(r){return" Function tester :: Runtime->> "+r+" ms Runned->> "+l+" times, Average->> "+(B.round((r/l)))+" ms"})},startTest:function(name){curTest=name=name||DF;tests[name]=new Test(name).start();return this},endTest:function(name){if(!tests[(curTest=name=name||curTest||DF)]){return this}else{tests[name].end().output().reset()}return this},start:function(name){if(!name){this.startTest()}else{tests[curTest].start(name)}return this},end:function(name,endTest){if(!name){this.endTest()}else{tests[curTest].end(name)}if(endTest){this.endTest()}return this},result:function(n){return typeof tests[(n=n||curTest||DF)]==="object"?tests[n].result():0},enable:function(){enabled=true;return this},disable:function(){enabled=false;return this},output:function(avoidReset){var v=bufferd_output;if(!avoidReset){bufferd_output=""}return v},useAlert:function(){use_console=false;return this},useConsole:function(){use_console=true;return this},round:function(num,dec){dec=dec||5;return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)}});function Test(name){if(!(this instanceof Test)){return new Test(name)}this.bench=new B();this.reset();this.name=name;this._result=0}Test.prototype={start:function(name,v){name=name||this.name;this._start(v);if(!this.marks[name]){this.times[name]=this.marks[name]=0}this.bench.mark(name+_s);return this},_start:function(v){if(!v&&typeof this.marks[this.name]!=="number"){this.start(this.name,true)}return this},end:function(name){name=name||this.name;this.times[name]++;this.marks[name]+=this._result=this.bench.mark(name+_e,name+_s,false).result();return this},output:function(){var mark_len=(function(marks){var i=0,n;for(n in marks){i++}return i})(this.marks),more_detail=mark_len>2,i=0,name,time;if(more_detail){if(use_console){output()}output("Report for test->> '"+this.name+"' :")}for(name in this.marks){if(name!==this.name){time=this._outputTest(name,"end",function(times,time){i+=times;return times>1?", Runned->> "+times+" times, Average->> "+(B.round((time/times)))+" ms":" "})}}this._result=(mark_len!==2)?this._result=this._outputTest(this.name,(mark_len>2?"endTest":"end"),function(){return more_detail?", Total Tests->> "+i:" "}):time;this.reset();return this},result:function(){return this._result},_outputTest:function(name,fn,callback){var times=this.times[name],time=this.marks[name];output(fn+"('"+name+"') :: Runtime->> "+time+" ms"+(callback(times,time)||"{error}:_outputTest('"+name+"','"+fn+"')->> "+error_messages.callback));return time},reset:function(){this.bench.reset();this.marks={};this.times={};return this}};B.tester=Test;var tests={};tests[DF]=new Test(DF)})(jQuery);

