Quote:Original post by dmatter
wot does anyone think?
Thanx in advance :)
I think that this is probably a horrible micro-optimization that will provide no noticeable speed benifit after much wasted time.
That said, which one is faster will depend entirely on wheither or not you're using a lot of different values or not. If you're only using one value, at worst, the first version won't be any slower. If you're using many values, the first version could be much slower due to the fact that a new version of each function will be created on most compilers for each value, causing more page misses and so forth when calling the function. That said, I suspect they will likely both preform EXACTLY the same and compile into the EXACT same code (in release mode, disregarding the symbol information), the constructor and so forth completely inlined to calls to vector.
In any case, the only definitive answer is to try both of them in a real life example (not some pansy ass benchmark, I'm talking about plug it in to your existing code that's having preformance problems in this area - if you don't have such code, you're prematurely optimizing, which is a waste of your time) and compare. When you can't tell a difference between the two, you'll know you've been wasting your time :-).
As such, I'd make my pick based on flexibility/what I wanted to do. Unless I'm doing some major template meta-programming, this would mean snippet 2 is best, since you can choose the value at runtime.
[Edited by - MaulingMonkey on June 9, 2005 3:39:37 PM]