We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Display calculation time
Page Index Toggle Pages: 1
Display calculation time (Read 1216 times)
Display calculation time
Jan 21st, 2010, 1:11pm
 
I would like to print to the console how long a calculation time was, atm i use:

   long startTimeMin = minute();
   long startTimeSec = second();

with this at the end:

   println(" time: " + (minute()-startTimeMin) +" min "+ (second()-startTimeSec) +" sec");

The problem is that if it's 18:57 for example then it ends up in -7 min cause a new hour started.

The problem with millis() is that it's much harder to read, specialy since my upcoming calculation time will be between 8 and 12 hours.

Is there some trick to fix this?
Re: Display calculation time
Reply #1 - Jan 21st, 2010, 2:01pm
 
Code:
int start;
void setup()
{
// Probably near zero...
int start = millis();
}

void draw()
{
background(frameCount);
}

void mousePressed()
{
int end = millis();
int timeSpent = (end - start) / 1000; // Seconds spent
int h = timeSpent / 3600;
timeSpent -= h * 3600;
int m = timeSpent / 60;
timeSpent -= m * 60;
println("Spent: " +
h + " hours, " +
m + " minutes, " +
timeSpent + " seconds");
}

Tested with only a few minutes.
Re: Display calculation time
Reply #2 - Jan 21st, 2010, 2:52pm
 
Thx a lot, i'm going to test tonight if the hours run proper.

for who's intrested:

But this line before a big for loop or something:
Code:

   int startTime = millis();


And this one after
Code:

   printSpentTime(startTime);


Code:

void printSpentTime(int startTime){
 int end = millis();
 int timeSpent = (end - startTime) / 1000; // Seconds spent
 int h = timeSpent / 3600;
 timeSpent -= h * 3600;
 int m = timeSpent / 60;
 timeSpent -= m * 60;
 println("Spent: " +h + " hours, " +m + " minutes, " +timeSpent + " seconds");
}
Page Index Toggle Pages: 1