Board index FlightGear Development Nasal

Nasal: systime() ??!?

Nasal is the scripting language of FlightGear.

Nasal: systime() ??!?

Postby Necolatis » Sat Apr 02, 2016 7:46 am

So I decided to run systime() a couple of times, due to some strangeness in benchmarking my code.

This is run from nasal console, pressing execute manually for each entry, does these look strange to You also?:

Code: Select all
1459579070.698599
1459579071.693600
1459579072.510599
1459579073.343599
1459579074.139599
1459579112.871599
1459579113.607599
1459579114.343599
1459579115.168600
1459579115.804600
1459579116.707600
1459579117.449600
1459579118.207600
1459579118.925600
1459579119.748600
1459579120.395599
1459579121.921600
1459579122.108599
1459579122.309599


I am running Windows 7 64 bit. My PC supports High Precision Event Timer (HPET).

So anyone can figure out whats going on here? Is millisecond really supposed to be the highest precision available?

I asked a buddy to test this on his flightgear, and he does not have this strangeness (note though that his PC is fairly new, where mine was produced in 2008).
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal: systime() ??!?

Postby AndersG » Sat Apr 02, 2016 10:29 am

The systime() function returns the number of seconds since 1st of January 1970 as a double precision floating point number.
For a double precision floating point number (which, IIRC, is the only numeric type supported by Nasal) the number of significant decimal digits is about 15-17, so the printout seems appropriate.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Nasal: systime() ??!?

Postby PINTO » Sat Apr 02, 2016 5:33 pm

For those who can't see it, every number ends in approx. .xxx600, which isn't exactly the precision expected.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Nasal: systime() ??!?

Postby Necolatis » Sat Apr 02, 2016 8:41 pm

Yep, a half hour earlier when I tried to do the same, they all ended in .xxx700
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal: systime() ??!?

Postby AndersG » Sat Apr 02, 2016 9:29 pm

I see. It might be that the Windows 7 clock FG uses uses ticks of >=1 msec (you'll have to check the source and the Windows API documentation).
As systime() returns a time stamp that contains both date and time the clock source used might not be very high resolution.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Nasal: systime() ??!?

Postby Necolatis » Sat Apr 02, 2016 9:39 pm

Well, PINTO does not have that problem, and he is on Windows too I believe.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal: systime() ??!?

Postby AndersG » Sat Apr 02, 2016 10:05 pm

Necolatis wrote in Sat Apr 02, 2016 9:39 pm:Well, PINTO does not have that problem, and he is on Windows too I believe.


Yes, but is it the same version?
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Nasal: systime() ??!?

Postby Richard » Mon Apr 04, 2016 8:28 am

Necolatis wrote in Sat Apr 02, 2016 7:46 am:So I decided to run systime() a couple of times, due to some strangeness in benchmarking my code.
...
So anyone can figure out whats going on here? Is millisecond really supposed to be the highest precision available?


High resolution timers under Windows can indeed produce these sort of results[1]. The underlying call is GetSystemTimeAsFileTime. It depends on the hardware, (CPU, chipset etc) and many other things. This has been discussed on StackOverflow[2].

My experience is in agreement with the above - that you can measure to mS accuracy reliably, but any more precise only works sometimes.

As an aside both Windows and Linux aren't very good for realtime applications due to the variable nature of interrupt timer handling.

--------------
[1] https://msdn.microsoft.com/en-us/librar ... 08(v=vs.85).aspx
[2] http://stackoverflow.com/questions/1825 ... in-windows
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Re: Nasal: systime() ??!?

Postby Necolatis » Mon Apr 04, 2016 6:58 pm

Alright, thanks.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal: systime() ??!?

Postby Hooray » Mon Apr 04, 2016 7:09 pm

You may want to add a corresponding {{Note|}} to the API docs to make this better known
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest