1. Elapsed time check - less than a second
- Posted by CraigWelch 1 week ago
- 201 views
Is there a known way of measuring elapsed time for less than one second ?
2. Re: Elapsed time check - less than a second
- Posted by jmduro 1 week ago
- 194 views
Look at CCHris's hirestime (Windows only).
If it's about a delay, than Ryan Johnson's idlelib would do the job (function nanosleep).
Jean-Marc
3. Re: Elapsed time check - less than a second
- Posted by CraigWelch 1 week ago
- 200 views
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
4. Re: Elapsed time check - less than a second
- Posted by CraigWelch 1 week ago
- 190 views
Duplicate in error.
5. Re: Elapsed time check - less than a second
- Posted by jmduro 1 week ago
- 183 views
Here is the Windows version:
-- high resolution time functions coded by CCHris <ccuvier@free.fr>, v1.0: November 2004 include std/dll.e include std/machine.e include std/os.e include std/console.e constant p232=power(2,32) atom timeFactor, pTimeFactor, k32, pc, pq, rcp --*------------------------------------------------------* -- reference high resolution timer libraries --*------------------------------------------------------* if platform()!=WIN32 then puts(1, "This library will function correctly under Windows only.") abort(1) end if k32=open_dll("kernel32") if k32=-1 then puts(1, "kernel32.dll can\'t be opened.") abort(1) end if pq=define_c_func(k32,"QueryPerformanceFrequency",{C_UINT},C_UINT) pc=define_c_proc(k32,"QueryPerformanceCounter",{C_UINT}) if (pc=-1) or (pq=-1) then puts(1, "The current Windows version does not support hi-res timers.") abort(1) end if pTimeFactor = allocate(8) rcp=c_func(pq,{pTimeFactor})-1 if rcp=-1 then puts(1, "Your hardware does not support hi-res timers.") abort(1) end if timeFactor=0 if rcp>-1 then timeFactor=peek4u(pTimeFactor)+p232*peek4u(pTimeFactor+4) end if free(pTimeFactor) ------------------------------------------------------------------------------ --this function returns a more precise value than time(), if the functionality is available. global function HRT_time() -- Returns a time value which is precise up to the microsecond (in theory, to the tenth of a microsecond). -- If the library is not using the high resolution performance counters, this defaults to time(). atom a c_proc(pc,{pTimeFactor}) a=p232*peek4u(pTimeFactor+4)+peek4u(pTimeFactor) return a/timeFactor end function ------------------------------------------------------------------------------ function formatTime(atom secs) sequence s integer mn, sec, hund mn = floor(secs/60) sec = remainder(floor(secs),60) hund = remainder(floor(secs*100+0.5),100) return sprintf("%02d'%02d\"%02d", {mn, sec, hund}) end function ------------------------------------------------------------------------------ atom t0 = HRT_time() sleep(4.5) printf(1, "Temps = %s\n", {formatTime(HRT_time()-t0)}) maybe_any_key()

