Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }
Copy Source | Copy HTML private String testString = "" ; protected void setUp() throws Exception { int charCount = 50 * 1024 * 1024 ; Random rnd = new Random (); byte chars[] = new byte [charCount * 2 ]; rnd.nextBytes(chars); testString = new String (chars); } public long _testStringBuilderToArray() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(data[i]); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testStringBuilderCharAt() { long start = System.currentTimeMillis(); StringBuilder builder = new StringBuilder (testString.length()); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { builder.append(testString.charAt(i)); } String reverse = builder.toString(); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testArrayToArray() { long start = System.currentTimeMillis(); char reverseBytes[] = new char [testString.length()]; char data[] = testString.toCharArray(); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public long _testReflectionToArray() throws Exception { long start = System.currentTimeMillis(); Field stringClassValueField = String . class .getDeclaredField( "value" ); stringClassValueField.setAccessible( true ); char reverseBytes[] = new char [testString.length()]; char data[] = ( char [])stringClassValueField. get (testString); int len = testString.length(); for ( int i = len - 1 ; i >= 0 ; i--) { reverseBytes[len - i - 1 ] = data[i]; } String reverse = new String (reverseBytes); if ((reverse.charAt( 2 ) == 'd' ) && (len == 1 )) { //To avoid compiler optimization return 0 ; } long end = System.currentTimeMillis(); return (end - start); } public void testRunner() throws Exception { long value = 0 ; int testCount = 20 ; //StringBuilderToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderToArray(); } System. out .println( "_testStringBuilderToArray - " + ( value / testCount)); //_testStringBuilderCharAt value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testStringBuilderCharAt(); } System. out .println( "_testStringBuilderCharAt - " + ( value / testCount)); //_testArrayToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testArrayToArray(); } System. out .println( "_testArrayToArray - " + ( value / testCount)); //_testReflectionToArray value = 0 ; for ( int i = 0 ; i < testCount; i++) { value += _testReflectionToArray(); } System. out .println( "_testReflectionToArray - " + ( value / testCount)); }
Source: https://habr.com/ru/post/J58382/More articles:YouTubeの10の秘密チェックメイトは適切ですか?Google、ベクマベトフ、アンジェリーナ・ジョリー。 彼らは一緒に何ができますか?NVidia GPUはApple LeopardとWindowsを加速しますアドビが13の新製品をリリースOutpostユーザーがFirewall Free 2009に勝つ方法オランダでテストされた空飛ぶ車ベラルーシのウィキペディアのスキャンダル元のコードに基づいて強調表示されたコードを含むHTMLを作成するオンラインサービスDouble Commander 0.4.0ベータがリリースされましたAll Articles