-
-
Save hoffrocket/5542168 to your computer and use it in GitHub Desktop.
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
String.replace took: 222957 µs
StringUtils.replace took: 107535 µs
String.replace took: 70163 µs
StringUtils.replace took: 11121 µs
String.replace took: 70630 µs
StringUtils.replace took: 12234 µs