public static float run(double minSeconds,TimerProcedure procedure){
  long iter=0;
  long minMillis=(long)(minSeconds * 1000);
  long begin=System.currentTimeMillis();
  long limit=begin + minMillis;
  while (System.currentTimeMillis() < limit) {
    procedure.init();
    procedure.apply(null);
    iter++;
  }
  long end=System.currentTimeMillis();
  if (minSeconds / iter < 0.1) {
    begin=System.currentTimeMillis();
    for (long i=iter; --i >= 0; ) {
      procedure.init();
      procedure.apply(null);
    }
    end=System.currentTimeMillis();
  }
  long begin2=System.currentTimeMillis();
  int dummy=1;
  for (long i=iter; --i >= 0; ) {
    dummy*=i;
    procedure.init();
  }
  long end2=System.currentTimeMillis();
  long elapsed=(end - begin) - (end2 - begin2);
  return (float)elapsed / 1000.0f / iter;
}

public static float run ( double minSeconds , TimerProcedure procedure ) { long iter = 0 ; long minMillis = ( long ) ( minSeconds * 1000 ) ; long begin = System . currentTimeMillis ( ) ; long limit = begin + minMillis ; while ( System . currentTimeMillis ( ) < limit ) { procedure . init ( ) ; procedure . apply ( null ) ; iter ++ ; } long end = System . currentTimeMillis ( ) ; if ( minSeconds / iter < 0.1 ) { begin = System . currentTimeMillis ( ) ; for ( long i = iter ; -- i >= 0 ; ) { procedure . init ( ) ; procedure . apply ( null ) ; } end = System . currentTimeMillis ( ) ; } long begin2 = System . currentTimeMillis ( ) ; int dummy = 1 ; for ( long i = iter ; -- i >= 0 ; ) { dummy *= i ; procedure . init ( ) ; } long end2 = System . currentTimeMillis ( ) ; long elapsed = ( end - begin ) - ( end2 - begin2 ) ; return ( float ) elapsed / 1000.0f / iter ; }
executes procedure repeatadly until more than minseconds have elapsed .
