Created
October 10, 2014 09:41
-
-
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
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
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