Re: Elapsed time check - less than a second
- Posted by jmduro 1 week ago
- 186 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()

