Last active
October 22, 2022 10:41
-
-
Save OMGZui/eff803e04399653ac0e7d3d4f20d21d9 to your computer and use it in GitHub Desktop.
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 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