I designed a program aiming to measure time consumption while avoid System.currentTimeMillis()
threshold for tiny execution(may take less than 1 milli)(it will inevitably produce acceptable inaccuracy for extra operations), but the count
turns out to be 222 whatever statements inside the run()
method are(limited to basic algorithms). I cannot figure out any possible explanation, sounds incredible but maybe a lower limit for execution?
public static void main(String[] args) throws Exception{
long result=TinyTimer(new Runnable(){
@Override
public void run(){
double d=190283758/287365628;
}
});
System.out.println(result);
}
public static long TinyTimer(Runnable r){
long count=0;
long origin=System.currentTimeMillis();
while(System.currentTimeMillis()==origin){
r.run();
count++;
}
return count;
}