Nasal library: Difference between revisions

Jump to navigation Jump to search
→‎systime(): Fix example
(→‎systime(): Fix example)
Line 2,095: Line 2,095:
{{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]}}
{{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
|example1 = print("Unix time: ", systime()); # prints Unix time
|example2 = var t = systime(); # record time
|example2 = var myFunc = func(){
 
     for(var i = 0; i <= 10; i += 1){
var myFunc = func(){
        print("Interation #", i);
     var pos = geo.aircraft_position(); # get aircraft position
    }
    var info = geodinfo(pos.lat(), pos.lon()); # get info
}
}
 
var t = systime(); # record time
myFunc(); # run function
var t2 = systime(); # record new time
var t2 = systime(); # record new time
print("myFunc() took ", t2 - t, " seconds"); # print result
print("myFunc() took ", t2 - t, " seconds"); # print result

Navigation menu