Calculations in source

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Calculations in source

Post by BarryG »

Hi, if my source code has 86400*7 in it (to calculate 7 days for a seconds query) does the compiler internally do the calculation with each run, or does it replace it with 604800 in the compiled executable? Wanting to optimise my program as much as possible.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Calculations in source

Post by infratec »

To be safe, use a constant:

Code: Select all

#SecondsPerDay = 86400*7
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Calculations in source

Post by chi »

BarryG wrote:...does the compiler internally do the calculation with each run, or does it replace it with 604800 in the compiled executable?
The latter...

Code: Select all

MOV    rax,604800
(also as constant)
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: Calculations in source

Post by BarryG »

Thank you both.
Post Reply