Curious speed
Displaying 1-12 of 12 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Zip

Was getting panicked about how fast my program was running and started trying to various 'opimizations'. All unnessersary of course, as when I bothered checking it's managing 200 game loops in .9 seconds.

Anyway (now only out of curiousity), a question for gurus, which of these is faster:

x++;
if (x == 4) x = 0;

or:

if (x == 3) x = 0;
else x++;

And why is x--; giving me errors?

Zip

Posted on 2004-04-26 23:19:06

Zip

Hmm.. x--; works in the new version, but now automax 0 is being ignored in my config. Odd.

Zip

Posted on 2004-04-26 23:29:10

Gayo

I'm no expert, but I'd guess the second would be faster since it has one fewer increment operation.but is otherwise identical.

Posted on 2004-04-26 23:41:29

RageCage

thats a pretty lame optimization to make... no offence =p

Posted on 2004-04-28 20:24:11

geronimo

x++;
if(x&4) x=0;

Posted on 2004-04-28 21:21:52

Zip

@rage Just a tip: if you feel the need to add 'no offence' at the end of a comment you make, it's a sure sign you do, in fact, need to moderate your tone. Seeing as you started the only other reply to me 'wtf', and didn't say anything useful in either, please don't object if I ignore you from now on. By the way, if you'd have bothered reading my first post, I did say it was only curiousity.

@geronimo Interesting, is Bitwise AND really faster than a straight forward equality expresion? Is assign, if, assign faster than if assign, else, assign too?

Zip

Posted on 2004-04-28 22:32:17

RageCage

yikes! sry man

Posted on 2004-04-28 22:59:19

Zip

Was rather too harsh myself. By the way, you should keep your funny hollow circle effects, looks very cool, just needs to be sand dunes rather than grass.

Zip

Posted on 2004-04-28 23:26:43

geronimo

:: is Bitwise AND really faster than a straight forward equality expresion?

If you were writing C code or something else that would be compiled directly to machine code, yea, the bitwise operation would be much faster than the comparison operation. In the case of a script language, I'm not really sure, though.

I do believe time could be shaved by eliminating the if, if your intention is just to have x count from 0 to 3 repeatedly. Here's how:

x++;
x=x&3; // if x is 4 (100), it will become 0

or, i wonder if this is faster?
x=(x+1)&3;

Posted on 2004-04-29 04:10:21 (last edited on 2004-04-29 06:18:33)

Zip

Ooooh! Very nice. Getting rid of the if would be much better. I'll give this a go.

Zip

Posted on 2004-04-29 13:54:10

mcgrue

When comparing verge speed operations, just do


Autoexec() {

//the operation here

exit( str(systemtime) );
}


For each operation and then compare the values.

If the operation in question is less than a ms, slap each in a for-loop containing only that operation and loop it a few thousand times, then compare. The overhead for each should be the same, and therefore cancel out, and the difference should prove to be true (ie, although you won't know the absolute time of the operations, you will know the difference in speed between the slower one and the faster one.)

Although general programming assumptions like Big O and the such should prove true in vc, I'm not sure if the c assumptions hold up in vc. Test it and find out!

Posted on 2004-04-29 22:00:44

Zip

Done. :D

Obviously the differences are very small, and I didn't exactly run this as a scientific test (had other programs running and such) but strangely if...else wins. In normal c I'd have said conditionals take longer than assignments, so don't know where verge differes on that one.

Zip


for (y= 0; y < 10000000; y++)
{
//x++;
//if (x == 4) x = 0; //454

//if (x == 3) x = 0;
//else x++; //440

//x++;
//if(x&4) x=0; // 468

//x++;
//x=x&3; //447

//x=(x+1)&3; //454
}
exit("Thanks for not-playing this not-game! "+"Time count: "+str(timer));

Posted on 2004-05-01 00:20:47


Displaying 1-12 of 12 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.