What is the idea with Add(), Div() etc.?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

What is the idea with Add(), Div() etc.?

Post by Bugala »

I thought that using X = Add(x, 1) would be faster that using x = x + 1, but seems I was wrong:

Code: Select all

amount = 100000
x = 1000
y = 1000
a = 1000
b = 1000
c = 1000

StartTimer(1)
start = GetTimer(1)
For n = 0 To amount
x = Add(x, 1)
y = Add(y, 1)
a = Add(a, 1)
b = Add(b, 1)
c = Add(c, 1)
Next

Endtime = GetTimer(1)

timepassed = Endtime - start
TextOut(10, 10, "add time:"..timepassed)

start = GetTimer(1)
For n = 0 To amount
x = x + 1
y = y + 1
a = a + 1
b = b + 1
c = c + 1
Next

endtime = GetTimer(1)
timepassed = endtime - start
TextOut(10, 100, "x+x time:"..timepassed)

WaitLeftMouse()
Resulting on my machine:
add time: 66
x + x time: 45

Which makes me wonder what is the point with those Add(), Div() etc. commands, if they just make the program slower, and are not as handy to use as x = x+1?
User avatar
airsoftsoftwair
Posts: 5833
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: What is the idea with Add(), Div() etc.?

Post by airsoftsoftwair »

These are old functions from the days of Hollywood 1.x. They are just there for compatibility with old scripts. You shouldn't use them in new code because they will be much slower than using operators because their use involves a function call while operators will directly map to VM opcodes.
Post Reply