lib/JSLitmus.js
function(count) {
      var me = this;

      // Make sure calibration tests have run
      if (!me.isCalibration && Test.calibrate(function() {me.run(count);})) return;
      this.error = null;

      try {
        var start, f = this.f, now, i = count;

        // Start the timer
        start = new Date();

        // Now for the money shot.  If this is a looping function ...
        if (this.loopArg) {
          // ... let it do the iteration itself
          f(count);
        } else {
          // ... otherwise do the iteration for it
          while (i--) f();
        }

        // Get time test took (in secs)
        this.time = Math.max(1,new Date() - start)/1000;

        // Store iteration count and per-operation time taken
        this.count = count;
        this.period = this.time/count;

        // Do we need to do another run?
        this.running = this.time <= this.MIN_TIME;

        // ... if so, compute how many times we should iterate
        if (this.running) {
          // Bump the count to the nearest power of 2
          var x = this.MIN_TIME/this.time;
          var pow = Math.pow(2, Math.max(1, Math.ceil(Math.log(x)/Math.log(2))));
          count *= pow;
          if (count > this.MAX_COUNT) {
            throw new Error('Max count exceeded.  If this test uses a looping function, make sure the iteration loop is working properly.');
          }
        }
      } catch (e) {
        // Exceptions are caught and displayed in the test UI
        this.reset();
        this.error = e;
      }

      // Figure out what to do next
      if (this.running) {
        me.run(count);
      } else {
        jsl.status('');
        me.onStop(me);
      }

      // Finish up
      this.onChange(this);
    }
function(count) {
      var me = this;

      // Make sure calibration tests have run
      if (!me.isCalibration && Test.calibrate(function() {me.run(count);})) return;
      this.error = null;

      try {
        var start, f = this.f, now, i = count;

        // Start the timer
        start = new Date();

        // Now for the money shot.  If this is a looping function ...
        if (this.loopArg) {
          // ... let it do the iteration itself
          f(count);
        } else {
          // ... otherwise do the iteration for it
          while (i--) f();
        }

        // Get time test took (in secs)
        this.time = Math.max(1,new Date() - start)/1000;

        // Store iteration count and per-operation time taken
        this.count = count;
        this.period = this.time/count;

        // Do we need to do another run?
        this.running = this.time <= this.MIN_TIME;

        // ... if so, compute how many times we should iterate
        if (this.running) {
          // Bump the count to the nearest power of 2
          var x = this.MIN_TIME/this.time;
          var pow = Math.pow(2, Math.max(1, Math.ceil(Math.log(x)/Math.log(2))));
          count *= pow;
          if (count > this.MAX_COUNT) {
            throw new Error('Max count exceeded.  If this test uses a looping function, make sure the iteration loop is working properly.');
          }
        }
      } catch (e) {
        // Exceptions are caught and displayed in the test UI
        this.reset();
        this.error = e;
      }

      // Figure out what to do next
      if (this.running) {
        me.run(count);
      } else {
        jsl.status('');
        me.onStop(me);
      }

      // Finish up
      this.onChange(this);
    }
function ( count ) { var me = this ; // Make sure calibration tests have run if ( ! me . isCalibration && Test . calibrate ( function ( ) { me . run ( count ) ; } ) ) return ; this . error = null ; try { var start , f = this . f , now , i = count ; // Start the timer start = new Date ( ) ; // Now for the money shot.  If this is a looping function ... if ( this . loopArg ) { // ... let it do the iteration itself f ( count ) ; } else { // ... otherwise do the iteration for it while ( i -- ) f ( ) ; } // Get time test took (in secs) this . time = Math . max ( 1 , new Date ( ) - start ) / 1000 ; // Store iteration count and per-operation time taken this . count = count ; this . period = this . time / count ; // Do we need to do another run? this . running = this . time <= this . MIN_TIME ; // ... if so, compute how many times we should iterate if ( this . running ) { // Bump the count to the nearest power of 2 var x = this . MIN_TIME / this . time ; var pow = Math . pow ( 2 , Math . max ( 1 , Math . ceil ( Math . log ( x ) / Math . log ( 2 ) ) ) ) ; count *= pow ; if ( count > this . MAX_COUNT ) { throw new Error ( 'Max count exceeded.  If this test uses a looping function, make sure the iteration loop is working properly.' ) ; } } } catch ( e ) { // Exceptions are caught and displayed in the test UI this . reset ( ) ; this . error = e ; } // Figure out what to do next if ( this . running ) { me . run ( count ) ; } else { jsl . status ( '' ) ; me . onStop ( me ) ; } // Finish up this . onChange ( this ) ; }
The nuts and bolts code that actually runs a test
The nuts and bolts code that actually runs a test