Nasal library: Difference between revisions

Jump to navigation Jump to search
Line 2,089: Line 2,089:
}}
}}
=== systime() ===
=== systime() ===
Returns epoch time (time since 1970/01/01 00:00) in seconds as a floating point number with high resolution. This is useful for benchmarking purposes.
{{Nasal doc
|syntax = systime();
|source = {{flightgear file|src/Scripting/NasalSys.cxx|l=770|t=Source}}
|text = Returns the {{wikipedia|Unix time}} (seconds since since 00:00:00 UTC, 1/1/1970) as a floating point number with high resolution. This function is useful for benchmarking purposes (see example 2).
{{note|1=High resolution timers under Windows can produce inaccurate or fixed sub-millisecond results.<ref>{{cite web|url=http://forum.flightgear.org/viewtopic.php?f=30&t=29259|title=Nasal: systime() ??!?|author=Necolatis|date=Apr 2nd, 2016}}</ref> This is due to the underlying {{func link|GetSystemTimeAsFileTime()|ext=https://msdn.microsoft.com/en-us/library/windows/desktop/ms724397(v=vs.85).aspx}} API call, which depends on hardware availability of suitable high resolution timers. See also [https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx Acquiring high-resolution time stamps]}}
|example1 = print("Unix time: ", systime()); # prints Unix time
|example2 = var t = systime(); # record time


{{caution|1=High resolution timers under Windows can produce inaccurate or fixed sub-millisecond results.<ref>{{cite web|url=http://forum.flightgear.org/viewtopic.php?f=30&t=29259|title=Nasal: systime() ??!?|author=Necolatis|date=Apr 2nd, 2016}}</ref> This is due to the underlying [https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx GetSystemTimeAsFileTime] Win32API call, which depends on hardware availability of suitable high resolution timers.}}
var myFunc = func(){
    var pos = geo.aircraft_position(); # get aircraft position
    var info = geodinfo(pos.lat(), pos.lon()); # get info
}
 
var t2 = systime(); # record new time
print("myFunc() took ", t2 - t, " seconds"); # print result
}}<!--


<!--
=== history() (3.1+) ===
=== history() (3.1+) ===


Navigation menu