Skip to content

Instantly share code, notes, and snippets.

@OMGZui
Last active October 22, 2022 10:41
Show Gist options
  • Save OMGZui/eff803e04399653ac0e7d3d4f20d21d9 to your computer and use it in GitHub Desktop.
Save OMGZui/eff803e04399653ac0e7d3d4f20d21d9 to your computer and use it in GitHub Desktop.
public class ReflectDemo {
public static void main (String[] args) throws IllegalAccessException, InstantiationException {
proxyObject();
newObject();
}
public static void newObject(){
long startTime = System.currentTimeMillis ();
int i;
for (i = 0; i < 100000000; i++) {
ReflectDemo reflectDemo = new ReflectDemo ();
}
if (i == 100000000) {
long endTime = System.currentTimeMillis ();
System.out.println ("new time:" + (endTime - startTime));
}
}
public static void proxyObject() throws IllegalAccessException, InstantiationException {
long startTime = System.currentTimeMillis ();
Class<ReflectDemo> reflectDemoClass = ReflectDemo.class;
int i;
for (i = 0; i < 100000000; i++) {
ReflectDemo reflectDemo = reflectDemoClass.newInstance ();
}
if (i == 100000000) {
long endTime = System.currentTimeMillis ();
System.out.println ("reflection time:" + (endTime - startTime));
}
}
}
new time:3
reflection time:230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment