Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created December 8, 2013 17:43
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 geNAZt/7860816 to your computer and use it in GitHub Desktop.
Save geNAZt/7860816 to your computer and use it in GitHub Desktop.
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