Re: Elapsed time check - less than a second

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks for that. I'm running on Linux, and should have so stated in my post.

Meanwhile, I asked Claude to tackle the problem. A few seconds later, I had a complete solution !

hires_time.e

include dll.e 
include machine.e 
 
constant 
    CLOCK_MONOTONIC = 1, 
    NANO = 1_000_000_000, 
    TS_SIZE = 16     -- struct timespec: 2 x 64-bit long on x86_64 
 
atom libc = open_dll("libc.so.6") 
 
integer clock_gettime = define_c_func( 
    libc, 
    "clock_gettime", 
    { C_INT, C_POINTER }, 
    C_INT 
) 
 
atom ts_mem = allocate(TS_SIZE) 
 
public function hires_time() 
    c_func(clock_gettime, { CLOCK_MONOTONIC, ts_mem }) 
 
    atom sec  = peek8u(ts_mem) 
    atom nsec = peek8u(ts_mem + 8) 
 
    return sec + nsec / NANO 
end function 
 

Invoked by:

 
include hires_time.e 
 
atom t0 = hires_time() 
 
-- work 
 
atom t1 = hires_time() 
 
printf(1, "Elapsed = %.9f seconds\n", t1 - t0) 
 

Which give as a result:

 
 Elapsed = 0.215912 seconds 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu