這篇文章裏面講到了幾點有關於效能改進的!
下面列出幾點來說明
A somewhat more radical idea is to slice up multidimensional arrays into parallel single one-dimension arrays
意思是說建立一個多維陣列的效能會比建立多個平行式的一維陣列來的差!When processing strings, don't hesitate to use specialty methods like String.indexOf(), String.lastIndexOf(), and their cousins. These are typically implemented in C/C++ code that easily runs 10-100x faster than doing the same thing in a Java loop.
意思是說不要猶豫使用indexOf()等等String.method之類!因為他們都是用C/C++去implement的!他們會比用JAVA迴圈來的快!
If you don't need to access an object's fields, make your method static. It can be called faster, because it doesn't require a virtual method table indirection
最後一點是,避免使用getter/setter,
下列有段code,看出瑕疵的地方嗎?
for (int i = 0; i < this.getCount(); i++)
dumpItems(this.getItem(i));
答案就是別在for迴圈作this.getCount()這種操作!很浪費!!
請先宣告個變數,再放到FOR迴圈裡面