Created
July 5, 2020 18:22
-
-
Save hugo4715/e44cc7db500285f09407d34993d4dd55 to your computer and use it in GitHub Desktop.
This file contains 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
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
class Scratch { | |
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | |
TestClass testClass = new TestClass(); | |
long time = System.currentTimeMillis(); | |
for (int i = 0; i < 10000000; i++) { | |
testClass.getClass().getMethod("test").invoke(testClass); | |
} | |
System.out.println(System.currentTimeMillis()-time + "ms"); | |
time = System.currentTimeMillis(); | |
Method method = testClass.getClass().getMethod("test"); | |
for (int i = 0; i < 10000000; i++) { | |
method.invoke(testClass); | |
} | |
System.out.println(System.currentTimeMillis() - time + "ms"); | |
} | |
static class TestClass{ | |
private int a; | |
public void test(){ | |
a++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment