Monday, October 02, 2006

[Matlab][Cpp] Time Telling

[Matlab] Generate file name with time

Codes:

currTime = clock;
fname = sprintf('myfilename_%02d%02d%02d%02d.txt', currTime(2:5) );

[Matlab]Timer
Measure how many seconds were elapsed.

Source:

Matlab Help

Codes:

t1 = clock;
%%%%%%%%%%%%%%%%
% Run your scripts
%%%%%%%%%%%%%%%%
t2 = clock;
Elapsed = etime(t2,t1);

[CPP] Timer Code
Measure how many seconds were elapsed.

Source:

http://www.cplusplus.com/ref/ctime/time.html

Codes:

#include <time.h>
time_t stime, etime;
stime = time(NULL);
...<Codes to be timed.>...
etime = time(NULL);
printf("Time elapsed: %ld seconds\n", etime-stime);

[CPP] Wait function
Make the program wait for several seconds.

Source:

http://www.cplusplus.com/ref/ctime/clock.html

Codes:

#include <time.h>

int seconds = 10;
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}

[CPP] Print time/date info
Print the current date and time

Source:

http://www.cplusplus.com/reference/clibrary/ctime/ctime.html

Codes:

#include <stdio.h>
#include <time.h>

int main ()
{
time_t rawtime;

time ( &rawtime );
printf ( "The current local time is: %s", ctime (&rawtime) );

return 0;
}