Created
May 8, 2013 17:45
-
-
Save anonymous/5542156 to your computer and use it in GitHub Desktop.
micro benchmark of String.replace vs StringUtils.replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang.StringUtils; | |
public class ReplaceTime | |
{ | |
static final int LOOPS = 100000; | |
static void timeReplace() { | |
long start = System.nanoTime(); | |
for (int i = 0; i < LOOPS; i++) { | |
"foo;bar;car".replace(";", "%3B"); | |
} | |
System.out.println("String.replace took: " + (System.nanoTime() - start)/1000 + " µs"); | |
} | |
static void timeStringUtilsReplace() { | |
long start = System.nanoTime(); | |
for (int i = 0; i < LOOPS; i++) { | |
StringUtils.replace("foo;bar;car", ";", "%3B"); | |
} | |
System.out.println("StringUtils.replace took: " + (System.nanoTime() - start)/1000 + " µs"); | |
} | |
public static void main( String[] args ) | |
{ | |
timeReplace(); | |
timeStringUtilsReplace(); | |
timeReplace(); | |
timeStringUtilsReplace(); | |
timeReplace(); | |
timeStringUtilsReplace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment