pouët.net

the effectiveness of code

category: general [glöplog]
c++ or ++c ?
added on the 2009-07-24 00:08:53 by cxnull cxnull
Thanks for the info guys. Preacher's example was very useful for me and basically answered my question.

Note that in all of my programm there are no long loops and come to think of it, I don't remember using any loops at all.

I also heard that the switch statement is generally faster than if. Maybe for keyboard events it is better to use the switch statement - to look for key codes. But maybe I won't bother changing the code now since it works alright.
hermes: why the sources are shouting? :(
added on the 2009-07-24 08:53:19 by decipher decipher
They couldn't afford lower case letters back then. Also, everything was mostly in black and white because they'd just started inventing colors :/
added on the 2009-07-24 09:27:27 by Preacher Preacher
"I also heard that the switch statement"

Louigi Verona, please stop here right now.

Mesure! Look at the assembly code! (With the compiler you're using)

Don't listen to people and their recipes. There is ton of obsolete information out there.

And optimization is not a set of magic practices that wizard teach you.


added on the 2009-07-24 09:53:06 by _-_-__ _-_-__
yeah good luck measuring those. maybe you should get an atomic clock for those measurements.
added on the 2009-07-24 10:08:01 by decipher decipher
Decipher, your comment underlines something I also forgot to mention, which is that optimization is best done after having set some sort of goal. And anything that does not substantially help reaching that goal is useless.

added on the 2009-07-24 10:11:26 by _-_-__ _-_-__
Decipher, BECAUSE IT'S WRITTEN IN FORTRAN77!

no lowercase allowed :-)
added on the 2009-07-24 10:21:17 by torus torus
that's not F77, that's some sort of assembler code.

but yeah, it's definitely transcribed from some punch-card by the looks of it :)
added on the 2009-07-24 10:34:47 by ryg ryg
Yeah that's asm code for AGC processors.
added on the 2009-07-24 10:57:27 by hitchhikr hitchhikr
I think it's some unique cpu too (AGC CPU)

http://www.ibiblio.org/apollo/
added on the 2009-07-24 10:58:40 by _-_-__ _-_-__
All this stuff is well and good, but replacing an if with a switch here and there will make virtually zero difference unless you're on a super slow processor or running it 1000s of times in a loop. Optimising the algorithm should always be the first stop.

I had to optimise some of my code recently, and managed to get it to >10x faster, and <10% of the memory usage, just by changing the algorithm. I didn't even bother to look at optimising things like if/else. (Of course, that's probably a result of my crappy initial code, maybe you're writing stuff efficiently first time :)
added on the 2009-07-24 11:11:57 by psonice psonice
psonice: Well, in this particular case the algorithm is very simple and event based. As I've said, there is not even a single loop in the whole app. All I was concerned of were those if's and I got a reply. As for optimization, I understand what you say and this is good advice.

you worry too much man :-)
if speed is not causing you problems, then it probably isn't. don't forget that computers are ridiculously fast.
added on the 2009-07-24 11:41:32 by skrebbel skrebbel
yeah, I really wonder how instead of just a well-deserved stop whining he got the tip to put branching hints in a freaking timer handler :)

as said many times in this thread: it's not fair to worry about such stuff in this context, if you do, just try to imagine the amount of things that your modern pc (<--) is doing BESIDES *your* program at that time ;)

now when there's actually something to optimize, these are good imho: http://www.agner.org/optimize/
added on the 2009-07-24 13:22:43 by superplek superplek
I can't imagine how keyboard button checking can be a bottleneck. do you guys query input zillion times a second or what?
but if the character I'm typing is the last in the if-else chain!!!!111one!
added on the 2009-07-24 14:26:07 by Puryx Puryx
Quote:
I can't imagine how keyboard button checking can be a bottleneck. do you guys query input zillion times a second or what?


OT, but.. If you follow good programming practice and only process events on the event thread and return quickly, guess what happens on android? :)
added on the 2009-07-24 14:49:50 by 216 216
don't put your esc keydown check inside the tight inner inner inner loop that is called for every pixel and computed every frame. imagine if this caused a pipeline hickups every single time.
added on the 2009-07-24 15:44:23 by neoneye neoneye
OMFG! *goes back to remove ESC check from inner loop* ;)
added on the 2009-07-24 16:43:03 by raer raer
Good suggestion neoneye. I have another question for optimising those inner-inner loops though.. after I write each pixel, what's the fastest way to upload the texture with opengl?
added on the 2009-07-24 17:01:47 by psonice psonice
Since this thread is obviously going down the drain as all threads do on Pouet, one last comment:
Quote:
I also heard that the switch statement is generally faster than if.

Not necessarily. Most compilers will generate little call tables if the switch only covers a small amount
of cases and the expression to be checked only covers a fairly linear amount of values. In the worst
case, your switch statement will be translated into many many IFs.

Anyhow, i guess __-_-___ sums it up pretty well. If speed becomes an issue, measure, read the
assembly code, see where the bottlenecks are and react then. If it's not broken, don't try to fix it ;-)
added on the 2009-07-24 17:10:13 by Paranoid Paranoid
and try to use multiple threads with concurring inputhandlers to make the code even more fun
added on the 2009-07-24 18:00:20 by the_Ye-Ti the_Ye-Ti
optimize: run; measure; think; modify; goto optimize;
added on the 2009-07-25 11:41:04 by rmeht rmeht
rmeht, you have to write something new somehow in your loop otherwise you're just degenerating into producing a constant.
added on the 2009-07-25 13:05:17 by _-_-__ _-_-__

login