-
-
Save tyrcho/1511016 to your computer and use it in GitHub Desktop.
should be even faster (size only called once)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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