开发者

I want to make a wrapped acces type for certain internals of one of classes and I have some performance questions

开发者 https://www.devze.com 2023-01-03 08:27 出处:网络
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 refer

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开发者_如何学JAVA. 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消