24.12.2013, 20:21
I am not sure if this speedtest is accurate but its still shows that switch is faster than ternary operator, using Slice Pawn Playground switch prints Null( 0 ), but I am not sure if my code is right, but Ternary Operator prints around 70+
Switch speed test Code
Result
Ternary Operator speed test code
Result
Correct me if I did anything wrong on my code, and test it your self using this link: http://slice-vps.nl:7070/
Switch speed test Code
pawn Code:
#include <a_samp>
main()
{
new
StartCount,
EndCount,
i
;
StartCount = GetTickCount();
while(++i < 1000)
{
switch(i)
{
case 1000: print(" ");
}
}
EndCount = GetTickCount();
printf("Switch Statement Speed to locate 1000 i's: %d", (EndCount - StartCount));
}
Code:
Switch Statement Speed to locate 1000 i's: 0 Error: read EIO (EIO) The server stopped.
pawn Code:
#include <a_samp>
main()
{
new
StartCount,
EndCount,
i
;
StartCount = GetTickCount();
while(++i < 1000)
{
print(( i == 1000 ) ? ( " " ) : ( " " ));
}
EndCount = GetTickCount();
printf("Ternary Operator Speed to locate 1000 i's: %d", (EndCount - StartCount));
}
Code:
Ternary Operator Speed to locate 1000 i's: 72 Error: read EIO (EIO) The server stopped.