Skip to content

Instantly share code, notes, and snippets.

@daliborfilus
Created December 10, 2011 18:36
Show Gist options
  • Save daliborfilus/1455895 to your computer and use it in GitHub Desktop.
Save daliborfilus/1455895 to your computer and use it in GitHub Desktop.
hashtable/hashmap java benchmark
package benchmarks;
import java.util.Hashtable;
//import java.util.Map;
//import java.util.HashMap;
class Hash {
public static void main(String[] args) {
Integer i = new Integer(0);
//int i = 0;
Hashtable h = new Hashtable();
//Map<Integer, String> h = new HashMap<Integer, String>();
System.out.println("Running..");
i = 0;
while(i < 10000000)
{
//h.put(i, "aaa" + i);
h.put(i, "aaa" + i.toString());
if(i < 100)
{
// System.out.println(String.format("aaa%d", i));
System.out.printf("aaa%d\n", i);
}
i += 1;
}
}
}
// int, hashmap, server = 7,3s
// Integer, hashmap, server = 13,8s
// Integer, hashmap, server, explicit toString = 14,0
// int, hashtable, server = 8,1s
// Integer, hashtable, server = 15,6s
// Integer, hashtable, server, explicit toString = 15,1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment