Ruud H.G. van Tol on Fri, 21 Oct 2022 18:10:56 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: suggestion: timer format



Hello Markus,

Example timing wrapper:

? timethis( E )= {  /*--*/
default(timer, 0);

my
( ta= getabstime()
, tw= getwalltime()
, rv
);

iferr
( rv= E()
, ERR
, print("[ERROR] ", errname(ERR))
);

printf
( "cpu time: %.3fs, real time: %.3fs"
, (getabstime() - ta) / 1000
, (getwalltime() - tw) / 1000
);

rv
} /*--*/


It requires a "()->" prefix:

? timethis( ()-> my(v=1,w=2); alarm(1,while(1,1)); v/w )
cpu time: 1.003s, real time: 1.004s

%9 = 1/2

-- Ruud


On 2022-10-21 16:40, Markus Grassl wrote:

[...]
In my code, I just enable the built-in timing information using

   default(timer,1)

which will reported both the total CPU time and the wall clock (real time) spent on commands, e.g.,

   cpu time = 73h, 13min, 28,457 ms, real time = 2h, 12,222 ms.

It is again no big deal to write a script to parse this timing information, for which the number of minutes in the real time is zero and hence omitted in the printing. Yet another option would be to change the hard-coded printing format and compile an adjusted version of gp.

But I am thinking that others might also appreciate some flexibility for the built-in functions instead of adding their own time measurements to their code.