Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Replace nanoTime calls with a common routine #32

Open
prensing opened this issue Oct 27, 2020 · 1 comment
Open

Replace nanoTime calls with a common routine #32

prensing opened this issue Oct 27, 2020 · 1 comment

Comments

@prensing
Copy link
Member

nanoTime() returns integer nanoseconds, which is not directly useful. Make a common call to scale that to floating seconds and replace uses through the code.

System.nanoTime() / 1_000_000_000.0

@prensing
Copy link
Member Author

prensing commented Nov 1, 2020

BTW for reference, "1_000_000_000.0" is not a good way to write that number. Use "engineering notation": 1.0e9. It is short, compact, and easy to read.

Also, floating division is the slowest of the simple arithmetic operations, by a fair bit. So, it is faster (and certainly no slower) to write:
1.0e-9 * System.nanoTime()
Note the minus sign in "1.0e-9". Of course, this statement is not used much in the robot code, and pretty hard to measure an actual difference. I mention it for "academic" interest.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant