Computational performance — a beginner’s case study(lbrandy.com)
lbrandy.com
Computational performance — a beginner’s case study
http://lbrandy.com/blog/2009/07/computational-performanc-a-beginners-case-study/
9 comments
This is a good article, because it illustrates the counter-intuitive aspect of computer programming. We would think initially that they both should take the same amount of time, but due to the way information is represented in the computer, the times are vastly different.
What would be even better is if the compiler could realize that the loops are independent of each other and compiled either way to the better machine code. I don't think that'd be possible with C, but possibly C# or Java could have the JIT engine recognize such a scenario and make the proper optimization.
It is possible with C.
http://en.wikipedia.org/wiki/Loop_interchange
http://gcc.igor.onlinedirect.bg/summit/2004/High%20Level%20L...
http://en.wikipedia.org/wiki/Loop_interchange
http://gcc.igor.onlinedirect.bg/summit/2004/High%20Level%20L...
Oh cool, thanks for sharing. I learn something new every day here...
Nice article, I know I for one can give these issues little thought when coding at a higher level of abstraction but certainly necessary knowledge for performance critical code.
Given a large enough performance difference (and non-pathological code), is the answer ever "fewer op codes"?
That's why you have swizzling in textures (grouping close pixels (left,right,up,down) in close proximity).
It's worth remembering that C is an abstraction. Even assembly is an abstraction. If you care about performance, you need to understand the limitations of the abstraction level you're working at - where your abstraction leaks, and what it is that leaks through.