which is faster - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: which is faster (
/showthread.php?tid=634107)
which is faster -
TYDS - 13.05.2017
which is faster:
something = ++
something = something + 1
Re: which is faster -
Tord - 13.05.2017
The differences are insanely small, and I think they operate at the same speed.
you can try making one function with 100 such lines, and see which is faster.
Use
GetTickCount() in order to determine the speed.
You can safely use ++ to save yourself from typing a few extra letters.
Re: which is faster -
iLearner - 13.05.2017
Something++; is more used, never tested speeds
Re: which is faster -
Inceptio - 13.05.2017
Well, seems like Something ++; sometimes gets the player around 2k of "something" instead of one?
Re: which is faster -
Vince - 13.05.2017
Ugh, trying to optimize in nanoseconds again. Don't even bother benchmarking. Just go with whatever fits the situation, e.g.:
PHP код:
switch(foo)
{
case 1: bar += 1;
case 2: bar += 3;
case 3: bar += 5;
}
Here it makes more sense to use += 1 rather than ++ to make it easier on the eye.
Respuesta: which is faster -
Ignaciodmr - 13.05.2017
++ is faster however it's just nanoseconds and wont make a difference.
Re: which is faster -
SyS - 13.05.2017
++var is faster than var++ and var = var +1. But might not be fit equally for all purposes.
Re: which is faster -
Tord - 13.05.2017
Quote:
Originally Posted by SyS
++var is faster than var++ and var = var +1. But might not be fit equally for all purposes.
|
by how much? any documentation, even benchmarks made ?
Re: which is faster -
SyS - 13.05.2017
Quote:
Originally Posted by Tord
by how much? any documentation, even benchmarks made ? 
|
by minute value.I will explain why ++var is faster than var++.
var++ is postincrement operator which will take the copy of the var and then increment it and assigns.
++var is preincrement operator which will take the memory address (call by reference) and increments the value and does not require a temporary copy.
Re: which is faster -
Tord - 13.05.2017
Quote:
Originally Posted by SyS
by minute value.I will explain why ++var is faster than var++.
var++ is postincrement operator which will take the copy of the var and then increment it and assigns.
++var is preincrement operator which will take the memory address (call by reference) and increments the value and does not require a temporary copy.
|
I was not aware that postincrementing was possible in pawn. Thanks for letting me know, I'll run some tests on this.