Skip to content

Instantly share code, notes, and snippets.

@tyrcho
Forked from svenefftinge/gist:1506285
Created December 22, 2011 17:04
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 tyrcho/1511016 to your computer and use it in GitHub Desktop.
Save tyrcho/1511016 to your computer and use it in GitHub Desktop.
should be even faster (size only called once)
public static void main(String[] args) {
int iterations = 1000000;
Object[] items = {"foo", 23, true};
int size = items.length;
Object[] absoluteResult = new Object[iterations*size];
long before = System.currentTimeMillis();
for (int i=0; i < iterations; i++) {
for (int j=0 ; j< size; j++) {
absoluteResult[3*i+j]=foo(items[j]);
}
}
System.out.println("Took : "+(System.currentTimeMillis() - before)
+" ms, number of elements : "+absoluteResult.length);
}
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