05.02.2011, 08:01
It's fully explained in An in-depth look at binary and binary operators!
[12:20:55] Connected Players = 26 | Phantom Slots = 45 [12:20:55] ID: 0 | Connected: 1 | Received loop: Yes [12:20:55] ID: 1 | Connected: 1 | Received loop: Yes [12:20:55] ID: 2 | Connected: 1 | Received loop: Yes [12:20:55] ID: 3 | Connected: 1 | Received loop: Yes [12:20:55] ID: 4 | Connected: 1 | Received loop: Yes [12:20:55] ID: 5 | Connected: 0 | Received loop: No [12:20:55] ID: 6 | Connected: 0 | Received loop: No [12:20:55] ID: 7 | Connected: 1 | Received loop: Yes [12:20:55] ID: 8 | Connected: 1 | Received loop: Yes [12:20:55] ID: 9 | Connected: 1 | Received loop: Yes [12:20:55] ID: 10 | Connected: 1 | Received loop: Yes [12:20:55] ID: 11 | Connected: 0 | Received loop: No [12:20:55] ID: 12 | Connected: 0 | Received loop: No [12:20:55] ID: 13 | Connected: 1 | Received loop: Yes [12:20:55] ID: 14 | Connected: 1 | Received loop: Yes [12:20:55] ID: 15 | Connected: 0 | Received loop: No [12:20:55] ID: 16 | Connected: 1 | Received loop: Yes [12:20:55] ID: 17 | Connected: 0 | Received loop: No [12:20:55] ID: 18 | Connected: 0 | Received loop: No [12:20:55] ID: 19 | Connected: 1 | Received loop: Yes [12:20:55] ID: 20 | Connected: 1 | Received loop: Yes [12:20:55] ID: 21 | Connected: 1 | Received loop: Yes [12:20:55] ID: 22 | Connected: 1 | Received loop: Yes [12:20:55] ID: 23 | Connected: 0 | Received loop: No [12:20:55] ID: 24 | Connected: 1 | Received loop: Yes [12:20:55] ID: 25 | Connected: 1 | Received loop: Yes [12:20:55] ID: 26 | Connected: 0 | Received loop: No [12:20:55] ID: 27 | Connected: 0 | Received loop: No [12:20:55] ID: 28 | Connected: 1 | Received loop: Yes [12:20:55] ID: 29 | Connected: 0 | Received loop: No [12:20:55] ID: 30 | Connected: 1 | Received loop: Yes [12:20:55] ID: 31 | Connected: 1 | Received loop: Yes [12:20:55] ID: 32 | Connected: 0 | Received loop: No [12:20:55] ID: 33 | Connected: 0 | Received loop: No [12:20:55] ID: 34 | Connected: 0 | Received loop: No [12:20:55] ID: 35 | Connected: 0 | Received loop: No [12:20:55] ID: 36 | Connected: 1 | Received loop: Yes [12:20:55] ID: 37 | Connected: 0 | Received loop: No [12:20:55] ID: 38 | Connected: 0 | Received loop: No [12:20:55] ID: 39 | Connected: 1 | Received loop: Yes [12:20:55] ID: 40 | Connected: 1 | Received loop: Yes [12:20:55] ID: 41 | Connected: 1 | Received loop: Yes [12:20:55] ID: 42 | Connected: 0 | Received loop: No [12:20:55] ID: 43 | Connected: 0 | Received loop: No [12:20:55] ID: 44 | Connected: 1 | Received loop: Yes
Wow, I always doubted that the fastest play loop wouldn't work as it would finish before all connected players were cycled through a loop.. guess I was wrong as I finally tested it.
|
stock something() {
// I'll write some code here first
// Then I'll do some more stuff
// Now I need an if statement possible
if(someVariable == true) {
// Now I write some code here
stock something() {
// I write NOTHING here yet, I first write the ending bracket
}
// Only NOW I can continue writing code in the function
#include <a_samp> main() { new StartTick, StopTick; StartTick = GetTickCount(); for(new i; i < 1000000; i ++) { StartTick = (StartTick == 1) ? 0 : 1; StartTick = (StartTick == 1) ? 0 : 1; StartTick = (StartTick == 1) ? 0 : 1; StartTick = (StartTick == 1) ? 0 : 1; StartTick = (StartTick == 1) ? 0 : 1; } StopTick = GetTickCount(); printf("Ternary condition: %d MS", StopTick - StartTick); return; }
#include <a_samp> main() { new StartTick, StopTick; StartTick = GetTickCount(); for(new i; i < 1000000; i ++) { if(StartTick == 1) { StartTick = 0; } else { StartTick = 1; } if(StartTick == 1) { StartTick = 0; } else { StartTick = 1; } if(StartTick == 1) { StartTick = 0; } else { StartTick = 1; } if(StartTick == 1) { StartTick = 0; } else { StartTick = 1; } if(StartTick == 1) { StartTick = 0; } else { StartTick = 1; } } StopTick = GetTickCount(); printf("Normal condition: %d MS", StopTick - StartTick); return; }
lol. do you know about benchmarking? so do its yourself.
I never says anything without a reason/proof. Normal condition: 10760068 MS Ternary condition: 10955372 MS Код:
... |
main()
{
new start, StartTick, StopTick;
start = GetTickCount();
for(new i; i < 1000000; i ++)
{
StartTick = (StartTick == 1) ? 0 : 1;
StartTick = (StartTick == 1) ? 0 : 1;
StartTick = (StartTick == 1) ? 0 : 1;
StartTick = (StartTick == 1) ? 0 : 1;
StartTick = (StartTick == 1) ? 0 : 1;
}
StopTick = GetTickCount();
printf("Ternary condition: %d MS", StopTick - start);
start = GetTickCount();
for(new i; i < 1000000; i ++)
{
if(StartTick == 1)
{
StartTick = 0;
}
else
{
StartTick = 1;
}
if(StartTick == 1)
{
StartTick = 0;
}
else
{
StartTick = 1;
}
if(StartTick == 1)
{
StartTick = 0;
}
else
{
StartTick = 1;
}
if(StartTick == 1)
{
StartTick = 0;
}
else
{
StartTick = 1;
}
if(StartTick == 1)
{
StartTick = 0;
}
else
{
StartTick = 1;
}
}
StopTick = GetTickCount();
printf("Normal condition: %d MS", StopTick - start);
}
@[J]ulian
lol. WRONG TEST. EACH BENCHMARK SHOULD BE DONE SEPARATELY. like me. After Ternary benchmark, CPU/RAM get involved. as i said WRONG TEST. |
#define LOOPS (1000000)
public OnFilterScriptInit()
{
new tmp = 0;
new time = GetTickCount();
for(new i = 0; i < LOOPS; ++i)
{
if(i > -1) {
tmp = 1;
}
else {
tmp = 2;
}
}
printf("if else time == %dms", GetTickCount()-time);
time = GetTickCount();//reset time
for(new i = 0; i < LOOPS; ++i)
{
tmp = (i > -1)? 1:2;
}
printf("ternary time == %dms", GetTickCount()-time);
return 1;
}
[12:19:41] if else time == 273ms [12:19:42] ternary time == 266ms
@[J]ulian
WRONG TEST. EACH BENCHMARK SHOULD BE DONE SEPARATELY. like me. After Ternary benchmark, CPU/RAM get involved. as i said WRONG TEST. |
Your test is wrong, as you modify the starting time during the test, and so just get the current tick time as benchmark result. Thats also why you dont get proper results when running your both tests at once: the tick time is about the same so both tests seem to run with the same speed. The benchmark time of 10760068ms = 3 hours should already make the test suspicious.
If you still dont believe that your test doesnt work, try running it the other way round, the tenary test first, and then the if test. |