Which one is fastest loop?
#1

I want to know, which one is faster.

pawn Код:
for (new i; i < 1000000; i++)
    {

        if(PlayerInfo[i][pMember] == 4)
        {
                SendClientMessage(playerid.....
                 }
      }
pawn Код:
for (new i; i < 10000000; i++)
    {
    if(PlayerInfo[i][pMember] != 4) continue;

     SendClientMessage(playerid.........
    }
Reply
#2

Whats the point of looping that many times?


Regardless,

pawn Код:
for (new i; i < 10000000; i++)
    {
    if(PlayerInfo[i][pMember] != 4) continue;

     SendClientMessage(playerid.........
    }

I guess that would be faster, as you wouldnt be loading everything after continue..
Reply
#3

Just put some random value there.
Reply
#4

For players just use MAX_PLAYERS lol
Reply
#5

Quote:
Originally Posted by Shockey HD
Посмотреть сообщение
For players just use MAX_PLAYERS lol
GetMaxPlayers() is even better.
Reply
#6

The difference on them about the time they take to be executed is not something you should worry about!

Quote:
Originally Posted by Shockey HD
Посмотреть сообщение
Whats the point of looping that many times?
Benchmarking.

Quote:
Originally Posted by Shockey HD
Посмотреть сообщение
I guess that would be faster, as you wouldnt be loading everything after continue..
You're actually wrong. It executes an if statement, if the statement is true it goes on continue else in the code above.

The first one (without the use of continue) executes the if statement and if it's true, it executes the code directly and it doesn't have any other case so that makes it faster.

Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
GetMaxPlayers() is even better.
And why is that? It executes a function while MAX_PLAYERS is a const number.
Reply
#7

Im not stupid, i dont use it as part of my code. I writed a code, to test loop speed, because with small loop value you dont see difference. But i had to go and i posted part of the code here.
Reply
#8

Quote:
Originally Posted by AA9
Посмотреть сообщение
Im not stupid, i dont use it as part of my code. I writed a code, to test loop speed, because with small loop value you dont see difference. But i had to go and i posted part of the code here.
I have done some speedtest, using 100,000 iterations out of 500,000 sized array, I'd say using continue is much faster than using if statement. Here are some result and the code I used, you can test this code using Slice Pawn Playground | Result + Code: Source

NOTE: 500,000 sized array are not meant to be used! this is just an example code to prove which one of these code are faster.
Reply
#9

The size of your array doesn't matter in that code.
Even if you increase that to 2 billion, it doesn't matter because you're only using the first 100000 indices of it with the ITERATIONS value.

And the result is negligable.
Maximum 2 ms difference for 100000 iterations.
Reply
#10

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
The size of your array doesn't matter in that code.
Even if you increase that to 2 billion, it doesn't matter because you're only using the first 100000 indices of it with the ITERATIONS value.

And the result is negligable.
Maximum 2 ms difference for 100000 iterations.
That is true, the maximum difference I've got is 2 milliseconds

pawn Код:
/* Results
 
1. Testing Started
 
Without continue took 8 ms to execute 100000 iterations
With continue 7 ms to execute 100000 iterations
 
Testing Ended
 
2. Testing Started
 
Without continue took 10 ms to execute 100000 iterations
With continue 8 ms to execute 100000 iterations
 
Testing Ended
 
3. Testing Started
 
Without continue took 7 ms to execute 100000 iterations
With continue 7 ms to execute 100000 iterations
 
Testing Ended
 
4. Testing Started
 
Without continue took 8 ms to execute 100000 iterations
With continue 7 ms to execute 100000 iterations
 
Testing Ended
 
*/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)