I wondered how I can keep track of the duration of the computations conducted by Gauss. It looks like that there is more than one way of doing this. What is the most efficient and cleanest way of doing it? Can you please give an example? If I have procs in my code, where this duration procedure should be placed in my code? Thanks!
1 Answer
1
Generally, the usage of hidden global variables is discouraged. However, in this case, it might make sense. You could create a file with these contents:
// Create a global variable to use as a timer
// Make it long and ugly, since we will not have
// to reference it directly and this will make it
// less likely that another procedure would reference it
declare __my_code_start_seconds = 0;
// Procedure to set the global variable and start the timer
proc (0) = startCodeTimer();
// set the global time variable to the number
// of seconds since January 1, 1970
__my_code_start_seconds = timeutc();
endp;
proc (1) = printElapsedTime();
local elapsed_sec;
// Compute the number of seconds elapsed
// since 'startCodeTimer' was called
elapsed_sec = timeutc() - __my_code_start_seconds;
// Multiply by 100, because 'etstr'
// assumes that the input is in hundredths of a second
retp(etstr(elapsed_sec * 100));
endp;
then you can add the file with this code to your user library so it will always be available to you. Then you can just use the procedures to time your code, like this:
startCodeTimer();
// Wait 5 seconds
call sleep(5);
printElapsedTime();
and you should get output that looks like this:
5.00 seconds
Your Answer
1 Answer
Generally, the usage of hidden global variables is discouraged. However, in this case, it might make sense. You could create a file with these contents:
// Create a global variable to use as a timer
// Make it long and ugly, since we will not have
// to reference it directly and this will make it
// less likely that another procedure would reference it
declare __my_code_start_seconds = 0;
// Procedure to set the global variable and start the timer
proc (0) = startCodeTimer();
// set the global time variable to the number
// of seconds since January 1, 1970
__my_code_start_seconds = timeutc();
endp;
proc (1) = printElapsedTime();
local elapsed_sec;
// Compute the number of seconds elapsed
// since 'startCodeTimer' was called
elapsed_sec = timeutc() - __my_code_start_seconds;
// Multiply by 100, because 'etstr'
// assumes that the input is in hundredths of a second
retp(etstr(elapsed_sec * 100));
endp;
then you can add the file with this code to your user library so it will always be available to you. Then you can just use the procedures to time your code, like this:
startCodeTimer();
// Wait 5 seconds
call sleep(5);
printElapsedTime();
and you should get output that looks like this:
5.00 seconds