function clock() {
    var applet,
        options = Benchmark.options,
        template = { 'begin': 's$=new n$', 'end': 'r$=(new n$-s$)/1e3', 'uid': uid },
        timers = [{ 'ns': timer.ns, 'res': max(0.0015, getRes('ms')), 'unit': 'ms' }];

    // lazy defined for hi-res timers
    clock = function(bench) {
      var deferred = bench instanceof Deferred && [bench, bench = bench.benchmark][0],
          host = bench._host || bench,
          fn = host.fn,
          fnArg = deferred ? getFirstArgument(fn, 'deferred') : '',
          stringable = isStringable(fn),
          decompilable = has.decompilation || stringable,
          source = {
            'setup': getSource(host.setup, preprocess('m$.setup()')),
            'fn': getSource(fn, preprocess('f$(' + fnArg + ')')),
            'fnArg': fnArg,
            'teardown': getSource(host.teardown, preprocess('m$.teardown()'))
          },
          compiled = fn.compiled,
          count = host.count = bench.count,
          id = host.id,
          isEmpty = !(source.fn || stringable),
          name = host.name || (typeof id == 'number' ? '<Test #' + id + '>' : id),
          ns = timer.ns,
          result = 0;

      // init `minTime` if needed
      bench.minTime = host.minTime || (host.minTime = host.options.minTime = options.minTime);

      // repair nanosecond timer
      // (some Chrome builds erase the `ns` variable after millions of executions)
      if (applet) {
        try {
          ns.nanoTime();
        } catch(e) {
          // use non-element to avoid issues with libs that augment them
          ns = timer.ns = new applet.Packages.nano;
        }
      }

      if(!compiled) {
        // compile in setup/teardown functions and the test loop
        compiled = host.compiled = createFunction(preprocess('n$,t$'), interpolate(
          preprocess(deferred
            ? 'var d$=this,#{fnArg}=d$,r$=d$.resolve,m$=(m$=d$.benchmark)._host||m$,f$=m$.fn;' +
              'if(!d$.cycles){d$.resolve=function(){d$.resolve=r$;r$.call(d$);' +
              'if(d$.cycles==m$.count){#{teardown}\n}};#{setup}\nt$.start(d$);}#{fn}\nreturn{}'
            : 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count;#{setup}\n#{begin};' +
              'while(i$--){#{fn}\n}#{end};#{teardown}\nreturn{time:r$,uid:"#{uid}"}'),
          source
        ));

        try {
          if (isEmpty) {
            // Firefox may remove dead code from Function#toString results
            // http://bugzil.la/536085
            throw new Error('The test, ' + name + ', is empty. This may be the result of dead code removal.');
          }
          else if (!deferred) {
            // pretest to determine if compiled code is exits early, usually by a
            // rogue `return` statement, by checking for a return object with the uid
            host.count = 1;
            compiled = (compiled.call(host, ns) || {}).uid == uid && compiled;
            host.count = count;
          }
        } catch(e) {
          compiled = false;
          bench.error = e || new Error(String(e));
          host.count = count;
        }
        // fallback when a test exits early or errors during pretest
        if (decompilable && !compiled && !deferred && !isEmpty) {
          compiled = createFunction(preprocess('n$'), interpolate(
            preprocess((bench.error && !stringable
              ? 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count;'
              : 'function f$(){#{fn}\n}var r$,s$,i$=this.count;'
            ) + '#{setup}\n#{begin};while(i$--){f$()}#{end};#{teardown}\nreturn{time:r$}'),
            source
          ));

          try {
            // pretest one more time to check for errors
            host.count = 1;
            compiled.call(host, ns);
            host.compiled = compiled;
            host.count = count;
            delete bench.error;
          }
          catch(e) {
            host.count = count;
            if (!bench.error) {
              host.compiled = compiled;
              bench.error = e || new Error(String(e));
            }
          }
        }
      }
      // if no errors run the full test loop
      if (!bench.error) {
        result = compiled.call(deferred || host, ns, timer).time;
      }
      return result;
    };

    /*------------------------------------------------------------------------*/

    /**
     * Gets the current timer's minimum resolution (secs).
     */
    function getRes(unit) {
      var measured,
          begin,
          count = 30,
          divisor = 1e3,
          ns = timer.ns,
          sample = [];

      // get average smallest measurable time
      while (count--) {
        if (unit == 'us') {
          divisor = 1e6;
          if (ns.stop) {
            ns.start();
            while (!(measured = ns.microseconds())) { }
          } else {
            begin = timer.ns();
            while (!(measured = ns() - begin)) { }
          }
        }
        else if (unit == 'ns') {
          divisor = 1e9;
          begin = ns.nanoTime();
          while (!(measured = ns.nanoTime() - begin)) { }
        }
        else {
          begin = new ns;
          while (!(measured = new ns - begin)) { }
        }
        // check for broken timers (nanoTime may have issues)
        // http://alivebutsleepy.srnet.cz/unreliable-system-nanotime/
        if (measured > 0) {
          sample.push(measured);
        } else {
          sample.push(Infinity);
          break;
        }
      }
      // convert to seconds
      return getMean(sample) / divisor;
    }

    /**
     * Replaces all occurrences of `$` with a unique number and
     * template tokens with content.
     */
    function preprocess(code) {
      return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid));
    }

    /*------------------------------------------------------------------------*/

    // detect nanosecond support from a Java applet
    each(window.document && document.applets || [], function(element) {
      return !(timer.ns = applet = 'nanoTime' in element && element);
    });

    // check type in case Safari returns an object instead of a number
    try {
      if (typeof timer.ns.nanoTime() == 'number') {
        timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
      }
    } catch(e) { }

    // detect Chrome's microsecond timer:
    // enable benchmarking via the --enable-benchmarking command
    // line switch in at least Chrome 7 to use chrome.Interval
    try {
      if ((timer.ns = new (window.chrome || window.chromium).Interval)) {
        timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
      }
    } catch(e) { }

    // detect Node's microtime module:
    // npm install microtime
    if ((timer.ns = (req('microtime') || { 'now': 0 }).now)) {
      timers.push({ 'ns': timer.ns,  'res': getRes('us'), 'unit': 'us' });
    }

    // pick timer with highest resolution
    timer = reduce(timers, function(timer, other) {
      return other.res < timer.res ? other : timer;
    });

    // remove unused applet
    if (timer.unit != 'ns' && applet) {
      applet = (applet.parentNode.removeChild(applet), null);
    }
    // error if there are no working timers
    if (timer.res == Infinity) {
      throw new Error('Benchmark.js was unable to find a working timer.');
    }
    // use API of chosen timer
    if (timer.unit == 'ns') {
      extend(template, {
        'begin': 's$=n$.nanoTime()',
        'end': 'r$=(n$.nanoTime()-s$)/1e9'
      });
    }
    else if (timer.unit == 'us') {
      extend(template, timer.ns.stop ? {
        'begin': 's$=n$.start()',
        'end': 'r$=n$.microseconds()/1e6'
      } : {
        'begin': 's$=n$()',
        'end': 'r$=(n$()-s$)/1e6'
      });
    }

    // define `timer` methods
    timer.start = createFunction(preprocess('d$'),
      preprocess('var n$=this.ns,#{begin};d$.timeStamp=s$'));

    timer.stop = createFunction(preprocess('d$'),
      preprocess('var n$=this.ns,s$=d$.timeStamp,#{end};d$.elapsed=r$'));

    // resolve time span required to achieve a percent uncertainty of at most 1%
    // http://spiff.rit.edu/classes/phys273/uncert/uncert.html
    options.minTime || (options.minTime = max(timer.res / 2 / 0.01, 0.05));
    return clock.apply(null, arguments);
  }
Clocks the time taken to execute a test per cycle (secs).
@private
@param {Object} bench The benchmark instance.
@returns {Number} The time taken.