Elapsed Time Coding in Turing
Author |
Message |
Jared
|
Posted: Wed Nov 28, 2007 10:35 am Post subject: Elapsed Time Coding in Turing |
|
|
K I need an elasped time counter. So far I've got this.
code: |
var timeRunning : int
timeRunning := Time.Elapsed
put "This program has run ", timeRunning, " milliseconds"
|
It's in miliseconds. I know I can get minutes and second by dividing by 1000 and 60.
What I need is a solution to get it to display both minutes and seconds. ie: 'Program has run 1 min 26 seconds'
I'm thinking its something with modular division, but so far I've had no luck.
Thanks for your patience, and please help. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
richcash
|
Posted: Wed Nov 28, 2007 2:49 pm Post subject: Re: Elapsed Time Coding in Turing |
|
|
You have the total number of milliseconds. You want to know how many milliseconds are left over after you have broken it down to seconds. To do this, use mod.
code: | var milliseconds := timeRunning mod 1000 |
To find the total number of seconds in your program, you divide by 1000. Now you want the left over seconds after you break it down to minutes. So you use mod as we did above again.
code: | var seconds := timeRunning div 1000 mod 60 |
To find the total number of minutes, you divide the total number of seconds by 60 or the total number of milliseconds by 60000.
code: | var minutes := timeRunning div 60000 |
And so on. If you wanted to include hours then you want the left over minutes, and you would use mod above. Right?
code: | var timeRunning : int
timeRunning := Time.Elapsed
var milliseconds := timeRunning mod 1000
var seconds := timeRunning div 1000 mod 60
var minutes := timeRunning div 60000
put minutes, ":", seconds, ".", milliseconds |
|
|
|
|
|
|
Jestar
|
Posted: Wed Nov 28, 2007 3:40 pm Post subject: Re: Elapsed Time Coding in Turing |
|
|
Whats exactly is mod? i have never used that before. |
|
|
|
|
|
Dan
|
Posted: Wed Nov 28, 2007 3:47 pm Post subject: RE:Elapsed Time Coding in Turing |
|
|
mod is short for Modulo or Modulo Operation. It is commonaly repsented by % in some langues (c, c++, java, ect)
For more info on what it is/what it does check out this page: http://en.wikipedia.org/wiki/Modulo_operation |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
HeavenAgain
|
Posted: Wed Nov 28, 2007 3:54 pm Post subject: Re: Elapsed Time Coding in Turing |
|
|
mod is like, finding the remainder, so in this following example, 47 mod 11 will be 3
|
|
|
|
|
|
richcash
|
Posted: Sat Dec 01, 2007 1:27 pm Post subject: Re: Elapsed Time Coding in Turing |
|
|
Jared, did you get what I said? If so, then good. If not, then you don't HAVE to use modulus ...
In your code timeRunning is the total number of milliseconds. As you said, you can find the number of minutes with division.
code: | var minutes := timeRunning div 60000 |
Now find the total number of seconds with division and subtract off the number of seconds already counted in your minutes column (minutes * 60 to convert to seconds).
code: | var seconds := timeRunning div 1000 - minutes * 60 |
If you want the left over milliseconds, subtract the number of seconds already counted and subtract the number of minutes already counted from timeRunning.
code: | var milliseconds := timeRunning - seconds * 1000 - minutes * 60000 |
|
|
|
|
|
|
|
|