PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Performance questions

Guess I'm to lazy to conduct as series of tests myself so I just ask here ;)

1) Does namespacing impact anything on performance. Like doing MyNS::Function1(i).

2) Say I have a class with some structs in it. Does this take any performance hit: oImage.oPos.x = 1. How much performance gain do I get if I create a pointer to oImage.oPos and then use that for my x and y values (or in other cases more subvalues depending on which struct). I hope it doesn't have to query the stack for each dot (.) I have...

3) Which is the fastest? Doing a switch statement or doing "else if":s? Guess switch is the fastest...

Thanks!
A lot of it will be compiler specific.

However, my guesses would be:

1) No idea - I'd /presume/ no performance hit 'cos it's more a compiler directive than actual code.

2) In theory, creating a pointer to the structure only performs one dereference to the object, and will then use offsets to address the individual items.

The other way, you *might* be unlucky and have the compiler dereference the object twice... but any decent compiler should keep the dereferenced pointer cached for next use.

... it really does depend on the compiler. If you want to compile that bit of code as ARM and post it here, I/somebody can tell you which it's doing.

(Go to project ->C/C++->Category tab->Listing files-> Assembly with source code).. then look through the assembler files and chop and post the function.

3) We've been through this one before, IIRC. A switch will essentially compile to a large set of elseif statements. The best gain is to *order* the ifs/switches in the most frequent first.

If you've got quite a lot of items to check, use a switch - it's cleaner to read.

Cheers,

Refractor
Does the eVC ARM compiler qualify as a decent compiler? :)
No it doesn't. 'Someone who can be trusted on this' told me that handcrafted asm could speed up an application 100-500%. The ARM assembler is terrible.
I don't know any of this for a fact, because it is very compiler-specific. Generally it should be correct. :) Of course the best way to determine what is more efficient is to compare the asm generated by the compiler.

When it comes to overloaded classes, there are cases when the determination of which class' implementation to use cannot be determined until runtime. So specifying it explicitely could help performance since you force it to occur at compilation.

switch statements can be much more efficient depending on how many cases you have. The more cases you have the more efficient it is compared to if / else. Also, it is my understanding that if your case values are pretty continuous, better performance can be achieved. The ARM processor has instructions specifically designed for switch / case use. They require more cycles than a simple if / else, so they should only be used when you have more than 4 or 5 values you are testing against. If you have a particular value that occurs much more than any other, you can boost performance by checking for that value with an if statement. If that fails then you drop into your switch to check the multitude of other values.

Using a pointer to a specific element in deeply nested structs or classes can help performance. If the element is of a simple type, you are better off to store the value in a local var, instead of a pointer to the value. Obviously that is not practical if the element is a struct or class.

Dan East
IMVHO the ARM code produced by eVC++ isn't all that hot. I've certainly seen better ARM compilers (though none that produce code so easily for WINCE/PPC/PPC2k).

Dan - the ARM doesn't have specific instructions for switches (unless I've forgotten something, which given today's workload, is possible :wink:). Conditional execution helps, of course... and something like a branch table works very nicely when there are quite a few entries in succession (or sometimes even for large sets of data that's not continuous - you just leave "catches" in for that data that shouldn't appear). The only real problem is that you're effectively performing two branches in quick succession, shafting the pipeline both times. So, as Dan said, for a few options, forget it, but if you're doing a lot of ifs in a discrete range it's worth looking at (and obviously only if you think there would be a performance gain).

Cheers,

Refractor
BurningSheep · 27 May 2002, 15:58 UTC
refractor wrote:
the ARM doesn't have specific instructions for switches


You don't really need specific instructions for switches, you can use a jumptable, but I don't know whether this compiler translates it efficiently.
<Faint>

eVC++ does actually translate switches into branch-tables:


mov r3, r1, lsl #24
mov r3, r3, asr #24
sub r0, r3, #0x41 ; 0x41 = 65
cmp r0, #0x19 ; 0x19 = 25
addls pc, pc, r0, lsl #2
b |$L25630| ; 000005CC
b |$L25633| ; 000004FC
b |$L25634| ; 00000504
b |$L25635| ; 0000050C
b |$L25636| ; 00000514
b |$L25637| ; 0000051C
b |$L25638| ; 00000524
b |$L25639| ; 0000052C
b |$L25640| ; 00000534
b |$L25641| ; 0000053C
b |$L25642| ; 00000544
b |$L25643| ; 0000054C
b |$L25644| ; 00000554
b |$L25645| ; 0000055C
b |$L25646| ; 00000564
b |$L25647| ; 0000056C
b |$L25648| ; 00000574
b |$L25649| ; 0000057C
b |$L25650| ; 00000584
b |$L25651| ; 0000058C
b |$L25652| ; 00000594
b |$L25653| ; 0000059C
b |$L25654| ; 000005A4
b |$L25655| ; 000005AC
b |$L25656| ; 000005B4
b |$L25657| ; 000005BC
b |$L25658| ; 000005C4


(And please read what I've written before quoting me like that).
BurningSheep · 28 May 2002, 12:31 UTC
sorry mate, should've read better :mrgreen:
Guess I'm to lazy to conduct as series of tests myself so I just ask here

1) Does namespacing impact anything on performance. Like doing MyNS::Function1(i).


No impact.

2) Say I have a class with some structs in it. Does this take any performance hit: oImage.oPos.x = 1. How much performance gain do I get if I create a pointer to oImage.oPos and then use that for my x and y values (or in other cases more subvalues depending on which struct). I hope it doesn't have to query the stack for each dot (.) I have...


oImage.oPos.x is as fast to access as any variable in memory. Essentially each dot just adds a constant offset to the base address for oImage and all these constants are added at compile time. This should be the case even in really crappy compilers.

oImage->oPos->x would be a different story as in this case a number of pointers are read and used as
the base address when reading the next pointer variable.

This also means that creating a pointer to oImage->oPos and using that would degrade performance, perhaps not by alot, but it wouldn't help any either.

/Orpe
The best ARM compiler is the ARM SDT 2.5.?? their is an evalution CD floating around the GBA dev sites, and its the cleanest ARM compiler. As its made by ARM :)
jadam:
evalution CD floating


You mean "illegal copy and associated illegal-to-use crack".

You can order a real, free, CD from ARM with a much later development kit and still have a 60-day trial period (IIRC) if you want to trial it legally (well that's what I did, anyway).
yeah, thats what i mean, order it from ARM... refractor, how fast is it? is the compiled code better than eVC++ or couldnt get your PocketPC to work with it??

Would ARM offer support if you purchased the full $4000 version?? And no, i didnt mean Warezed version. That way, you wouldnt really get any support anyways, and some new software is becoming really hard to warez, such as the $5000 software that uses USB Keychains for the Serial Number, the only one i know of is Discreet Combustion for Mac OS X
They used to have hardware locks on the printerports before. I know 3DSMax uses that. Does that help? Nope, there are cracks...
I have no idea how good it is in an actual comparison - I've never done one. I didn't use it for PPC stuff - I pretended to be a hardware hacker for a while and played with an ARM7TDMI evaluation board, until the GBA came along... which had an LCD and everything to make development a little bit easier :D (debugging with a pair or serial ports and 4 LEDs sux a55).

For the PPC, the graphics bits I do in straight assembler, which is compatible with both the ARM tools and eVC++'s compiler (strangely enough ;)) - I may as well do the C/C++ stuff in eVC++ 'cos it's pretty much all of the GUI and a few other non-performance-related functions.

According to their web-site, spending $5500 on their node-locked ADS entitles you to a year's support.

(I meant to put a ;) in my previous post, sorry :))
where did you order the evalution?
The evaluation board I got from the UK, and the evaluation software I requested from ARM.

Their current evaluation suite is <a href="http://www.arm.com/devtools/ads_eval?OpenDocument">HERE</a>.

Cheers,

Refractor