18 lines
568 B
Text
18 lines
568 B
Text
fcn rateCounter(f,timeNRuns,secsToRun=Void){
|
|
now:=Time.Clock.time;
|
|
if(secsToRun){
|
|
then:=now + secsToRun;
|
|
N:=0; do{ f(); N+=1; }while(Time.Clock.time<then);
|
|
t:=Time.Clock.time - now;
|
|
println("%d runs in %s seconds = %.3f sec/run"
|
|
.fmt(N,Time.Date.toHMSString(0,0,t),t.toFloat()/N));
|
|
}
|
|
else{
|
|
do(timeNRuns){ f() }
|
|
t:=Time.Clock.time - now;
|
|
println("%s seconds to run %d times = %.3f sec/run"
|
|
.fmt(Time.Date.toHMSString(0,0,t),timeNRuns,
|
|
t.toFloat()/timeNRuns));
|
|
t
|
|
}
|
|
}
|