Require "HighResolutionTimer" -load up the module Package.cpath = "./Timer.so" -assuming Timer.so is in the same directory Wraps the High Resolution Timer Functions in Note: I compiled the HighResTimer.c to a shared library, Timer.so #!/bin/lua Now lets get it loaded up in a lua script, a. Int luaopen_HighResolutionTimer (lua_State *L) , Lua_pushnumber(L, frequencyTemp.QuadPart) ĭouble mNanoSecondsPerCount = 1000000000/(double)Frequenc圜ountPerSec ĭouble elapsedNano = (currTime - prevTime)*mNanoSecondsPerCount QueryPerformanceFrequency(&frequencyTemp) įrequenc圜ountPerSec = frequencyTemp.QuadPart Static int readHiResTimerFrequency(lua_State *L) installed via setup or if I downloaded and compiled lua, compiled in cygwin after installing lua (cant remember if I compile with: gcc -o Timer.so -shared HighResTimer.c -llua5.1 I wrote some lua compatible C code, compiled it to a shared library (.so file via gcc in cygwin), and then loaded it up in lua using package.cpath and require” “. I basically did what Kevlar suggested, but with a shared library rather than a DLL. I made a suitable solution for lua on Windows. Indeed, one could take a similar approaching using clock_gettime() to obtain nanosecond accuracy. Then the new lua gettimeofday() function can be called from lua to provide the clock time to microsecond level accuracy. Return tonumber(gettimeofday_sec) * 1000000 + tonumber(gettimeofday_usec) Local gettimeofday_struct = ffi.new("struct timeval")įfi.C.gettimeofday(gettimeofday_struct, nil) Int gettimeofday(struct timeval* t, void* tzp) via content_by_lua_file in OpenResty – without it you run into errors such as attempt to redefine 'timeval') if pcall(ffi.typeof, "struct timeval") then If you are using luajit enabled environment, such as OpenResty, then you can also use ffi to access C based time functions such as gettimeofday() e.g: (Note: The pcall check for the existence of struct timeval is only necessary if you’re running it repeatedly e.g. Although if you want fine grained millisecond accuracy then you may need to call ngx.update_time() first. If you’re using OpenResty then it provides for in-built millisecond time accuracy through the use of its ngx.now() function. * The IDs of the various system clocks (for POSIX.1b interval timers): user November 30, -0001 at 12:00 am Get current time in milliseconds.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |