Created
December 8, 2013 17:43
-
-
Save geNAZt/7860816 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.cubespace.LocaleTest; | |
import org.apache.commons.lang.LocaleUtils; | |
import java.util.HashMap; | |
import java.util.Locale; | |
public class Main { | |
private static final String loc = "en_US"; | |
private static final HashMap<String, Locale> lookup = new HashMap<String, Locale>(); | |
public static void main(String[] args) { | |
benchLocaleUtilLookup(); | |
benchLocaleLookupTable(); | |
} | |
private static void benchLocaleLookupTable() { | |
long start = System.currentTimeMillis(); | |
for(int i = 0; i < 100000000; i++) { | |
if(!lookup.containsKey(loc)) { | |
lookup.put(loc, LocaleUtils.toLocale(loc)); | |
} | |
Locale use = lookup.get(loc); | |
} | |
System.out.println((System.currentTimeMillis() - start) + " ms"); | |
} | |
private static void benchLocaleUtilLookup() { | |
long start = System.currentTimeMillis(); | |
for(int i = 0; i < 100000000; i++) { | |
Locale use = LocaleUtils.toLocale(loc); | |
} | |
System.out.println((System.currentTimeMillis() - start) + " ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment