看一下 Jakarta Commons Cookbook中文版 你会发现很多人家已经些好了
// Performance testing notes (JDK 1.4, Jul03, scolebourne)
// Whitespace:
// Character.isWhitespace() is faster than WHITESPACE.indexOf()
// where WHITESPACE is a string of all whitespace characters
//
// Character access:
// String.charAt(n) versus toCharArray(), then array[n]
// String.charAt(n) is about 15% worse for a 10K string
// They are about equal for a length 50 string
// String.charAt(n) is about 4 times better for a length 3 string
// String.charAt(n) is best bet overall
//
// Append:
// String.concat about twice as fast as StringBuffer.append
// (not sure who tested this)
本文分享了Java性能测试中的一些实用技巧,包括不同方法在字符串操作(如:charAt、toCharArray)、字符判断(如:isWhitespace)及字符串拼接(String.concat与StringBuffer.append)时的性能对比。
891

被折叠的 条评论
为什么被折叠?



