tags:

views:

36

answers:

2

I am writing an abstract matrix class (and some concrete subclasses) for use on very differing hardwares/architectures, etc. and I want to write a row and column type that provides a transparent reference to the rows and columns of the matrix.

However, I want to tune for performance, so I'd like this class to be essentially a compiler construct. In other words, I'm willing to sacrifice some dev time to making the overhead of these classes as small as possible.

I assume all (small) methods would want to be inline? Keep the structure small? Any other suggestions?

+1  A: 

Don't do it. Write your code naturally. Make an elegant design and clear design. Make it work. Then, run it with a profiler and see if you have any performance holes.

Daniel Daranas
Well the thing is that I want to pass these things around a lot. I need to be able to use rows and columns from arbitrary matrices and operate one them, once again without knowing knowing how the matrices are implemented.
Alex
+2  A: 

Design for efficiency golden rule number 1 is to really properly fully completely totally understand and appreciate all of the nuances of the environment in which you are working.

Including, but not limited to:

  • Understanding the costs of each compiler construct you are using
  • Understand how the compiler uses memory
  • Do a proper design on the back of an envelope or napkin. If it doesn't fit you're in trouble.
  • Build small examples and test / disassemble
  • Revisit the design.

Then write some realistic test cases and test on the disparate hardware to identify if there are performance issues; I've done this a few times and unless you're writing in assembler the performance hit can be in the strangest places.

If it's too slow add hardware. If you can't add hardware optimise.

Richard Harrison