舉例來説,考慮一下線程安全的StringBuffer的用法。
However, there is a performance penalty here, since a StringBuffer must work to transparently increase its size and shift the data around.
Given the single threaded nature of this benchmark, I was fully expecting Escape Analysis to elide the lock thus rendering StringBuffer performance equivalent to that of StringBuilder.
對String和StringBuffer來説,完成測評所需要的時間隨着計劃長度的增加呈指數級增長。
明確了這個基準測試的單線程化的本質後,我期待着逸出分析會消除鎖,從而將StringBuffer的*能提到了與StringBuilder相同的水平。
為創建串聯的字符串 “ssRights” ,編譯器將創建一個臨時的StringBuffer對象,調用StringBuffernd 三次,然後調用StringBufferring ,這意味着至少兩個對象的創建和幾個方法調用。