Skip to content

Instantly share code, notes, and snippets.

@ryantenney
Created December 30, 2011 04:51
Show Gist options
  • Select an option

  • Save ryantenney/1537951 to your computer and use it in GitHub Desktop.

Select an option

Save ryantenney/1537951 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.lang.*;
class Main {
public static void main (String[] args) throws java.lang.Exception {
int size = 65536;
Map m;
long starttime, endtime;
m = new HashMap();
starttime = System.currentTimeMillis();
for (int i = 0; size > i; ++i) {
m.put(new NObject(), true);
}
endtime = System.currentTimeMillis();
System.out.printf("Inserting %d evil elements took %d ms\n", size, endtime - starttime);
m = new HashMap();
starttime = System.currentTimeMillis();
for (int i = 0; size > i; ++i) {
m.put(new Object(), true);
}
endtime = System.currentTimeMillis();
System.out.printf("Inserting %d good elements took %d ms\n", size, endtime - starttime);
}
public static class NObject {
@Override public int hashCode() { return 1; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment