java - Setting unique timers in for loop -
i using loop , setting timer @ beginning, , ending @ end. loop repeats 3 times , gives me 3 values need want able compare timer values gives me in java , compute results biggest-smallest. that, need each timer have unique name cannot seem do. here example of code.
int j; for(j=1;j<=3;++j){ //...code { long starttime = system.nanotime(); //timer start //...code long estimatedtime = system.nanotime() - starttime; //timer end system.out.println(starttime + "_1"); } { timer comparison 3 timers }
as said, have values, need way compare them. "estimatedtime" value i'm comparing, ideally assign names "estimatedtime2" , "estimatedtime3" on second , third values.
you cannot declare variable different name "on fly", have save estimated time in array or other data structure (e.g., list) , index accordingly.
for example, do:
long[] times = new long[3]; (int j=0;j<3;++j) { //...code { long starttime = system.nanotime(); //timer start //...code times[j] = system.nanotime() - starttime; // times[0], times[1], times[2] system.out.println(starttime + "_1"); } { // timer comparison 3 timers } }
after loop completes execution, have 3 time estimations in times
array.
Comments
Post a Comment