Community Forum

Access system time in milliseconds?

Forum Overview >> Scripting

CategoryScripting
Created29.10.2017 13:54


Peter Vaiko (pvajko) 29.10.2017 13:54
Is there any way to get the real time in a millisecond granularity?

My script was causing the game to hang for a few seconds so I wanted to find out how much time it spends in that function. Tried to use dt from update() but that does not seem to include the time spent in scripts.

Carter Nb (Unknown) 29.10.2017 17:49
did you try using print(dt) inside the update function, at the end of the function?

Peter Vaiko (pvajko) 30.10.2017 00:37
Not sure what you mean, dt does not change while update() is executing. And at the next call, it does not seem to include the time spent in update, rather it seems to be the time between the last return from update() and the entry to update().

Also tried g_currentMission.time, but that seems to behave the same, it is just a cumulative total of dts.

Fred Zanella (fredzaza2) 30.10.2017 17:20
this can help you i think

https://www.lua.org/pil/22.1.html

Peter Vaiko (pvajko) 31.10.2017 12:50
Thanks, but obviously I started with looking up the Lua doc only to find out that disappointingly Lua has only second resolution.

Also, none of the os functions are available in the game engine.

If you want second resolution real time you can use getDate() in the game, but I'm looking for milliseconds here.

Andy Königsdorf (Unknown) 27.08.2018 21:39
I've the same problem and want to measure time in milliseconds between certain chunks inside of the update function so 'dt' is no solution.

Anybody got an idea how to do this?


PS: searched a little bit and there are other possibilities but they require access to external libraries. Is it possible in the game engine lua interpreter to access a dll?
> dllObject = require('NameOfDll');

If so I would dig a little deeper to build a timer.dll which would have a function just to return a timestamp with nanoseconds granularity by using QueryPerformanceCounter(long *lTimeStamp).



Note: Log in to post. Create a new account here.