[GAP Forum] command to retrieve current date/time

Alexander Konovalov alexk at mcs.st-andrews.ac.uk
Sun Nov 25 12:40:12 GMT 2012


Hello Frederic,

On 25 Nov 2012, at 11:34, Frederic Vanhove wrote:

> Hello,
> 
> I was wondering if there is any way to let GAP return the current date or time.

You may just use "Exec" this to print it:

gap> Exec("date");
Fri  4 Sep 2009 14:12:34 BST

The SCSCP package has also an auxiliary finction "CurrentTimestamp" to get it as a string:

gap> CurrentTimestamp();
"Tue 30 Mar 2010 11:19:38 BST"

> I know that using
> time;
> one can get the number of milliseconds the last operation took.
> 
> However, I would like to do a long computation, and I would want GAP to print from to time what he has done already and how long that has already taken.

'time;' gives you the CPU time in milliseconds. When I am doing measurements which require real time, my recipe is to use IO_gettimeofday from the IO package, which returns the current time up to microseconds:

gap> LoadPackage("io"); 
gap> curtime1:=IO_gettimeofday();
rec( tv_sec := 1255709571, tv_usec := 402983 )
gap> runtime:=function(t1,t2) return 1000000*(t2.tv_sec-t1.tv_sec)+t2.tv_usec-t1.tv_usec; end;
gap> curtime2:=IO_gettimeofday();
rec( tv_sec := 1255709571, tv_usec := 458394 )
gap> runtime(curtime1,curtime2);
55411

Hope this is useful,
Alexander





More information about the Forum mailing list