which is faster
#1

which is faster:
something = ++
something = something + 1
Reply
#2

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.
Reply
#3

Something++; is more used, never tested speeds
Reply
#4

Well, seems like Something ++; sometimes gets the player around 2k of "something" instead of one?
Reply
#5

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 
1bar += 1;
    case 
2bar += 3;
    case 
3bar += 5;

Here it makes more sense to use += 1 rather than ++ to make it easier on the eye.
Reply
#6

++ is faster however it's just nanoseconds and wont make a difference.
Reply
#7

++var is faster than var++ and var = var +1. But might not be fit equally for all purposes.
Reply
#8

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 ?
Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)