Daily Archives: January 21, 2007

Programming Optimization

© Copyright 1996-2004 by Paul Hsieh
http://www.azillionmonkeys.com/qed/optimize.html

Introduction

This is a page about the elusive subject of program performance optimization.  Before you proceed towards such lofty goals, you should examine your reasons  for doing so.  Optimization is but one of many desirable goals in software  engineering, and is often antagonistic to other important goals such as  stability, maintainability, and portability. At its most cursory level  (efficient implementation, clean non-redundant interfaces) optimization is  beneficial and should always be applied.  But at its most intrusive (inline  assembly, pre-compiled/self-modified code, loop unrolling, bit-fielding,  superscalar and vectorizing) it can be an unending source of time consuming  implementation and bug hunting.  Be cautious and wary of the cost of  optimizing your code.
…………………………………………………..
C++ Optimization Strategies and Techniques

The running time of IBVH

最开始写的IBVH程序release版render一个图片都要15多分钟;把程序里的一个除法结果保存,随后只是读取这个值,再加上一些可有可无的优化后,运行时间就降到了5分钟;真的没有想到就保存这么一个除法结果,对程序的效率贡献有这么大。但是这也造成了生成的图像中出现了若干细小的空洞,这在以前是没有的。有时感觉这个artifacts不能容忍。

这两天把程序写成了多线程版本,运行时间只减少了1分半,达到了3分半,虽然下降不多,但是也是在预料之中的。今天又把程序里所有使用vector的地方,在使用前先使用reserve()函数初始了要使用的空间,又使运算时间下降了1分半,现在基本上2分钟内就可以得到结果了。

但是这样的结果还是不行的,要达到实时看来只能把Point和Vector这两个类改写成C code了,并且去掉vector容量器的使用,估计还有希望。