Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This one prints : "Took : 31 ms, number of elements : 3000000"
public static void main(String[] args) {
int iterations = 1000000;
List<?> items = newArrayList("foo", 23, true);
List<Object> absoluteResult = new ArrayList<Object>(iterations*items.size());
long before = System.currentTimeMillis();
for (int i=0; i < iterations; i++) {
for (int j=0 ; j< items.size(); j++) {
absoluteResult.add(foo(items.get(j)));
}
}
System.out.println("Took : "+(System.currentTimeMillis() - before)
+" ms, number of elements : "+absoluteResult.size());
}
static String foo(Object s) {
if (s instanceof String) {
return "String";
} else if (s instanceof Boolean) {
return "Boolean";
} else if (s instanceof Integer) {
return "Integer";
} else {
throw new IllegalArgumentException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.