Skip to content

Instantly share code, notes, and snippets.

@AgentK20
Created October 10, 2014 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgentK20/5446a9e958b31666b968 to your computer and use it in GitHub Desktop.
Save AgentK20/5446a9e958b31666b968 to your computer and use it in GitHub Desktop.
Speed test for conversion of UUID (in String form) with dashes to no dashes
package net.hypixel;
public class RegexSpeedTest {
public static void main(String[] args) {
String s = "f59fde79-1ab0-499a-b9c3-fbe400e6fca3";
long start = System.currentTimeMillis();
for(int i=0; i<100_000; i++) {
regex(s);
}
long end = System.currentTimeMillis();
long start2 = System.currentTimeMillis();
for(int i=0; i<100_000; i++) {
replaceAll(s);
}
long end2 = System.currentTimeMillis();
System.out.println("Regex took "+(end-start)+"ms");
System.out.println("String fragmentation took "+(end2-start2)+"ms");
}
private static String regex(String input) {
return input.replaceAll("-", "");
}
private static String replaceAll(String input) {
return input.substring(0, 8)+input.substring(9, 13)+input.substring(14, 18)+input.substring(19, 23)+input.substring(24, 36);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment