Reflection invocation is a little bit more expensive comparing to the direct call, but it wasn't very slow and it's not slow at all now in JDK 6. It is looking up by name that takes long time.
Link: What are the performance costs involved in Java reflection? E.g., looking up a method by name and then invoking it.
Operation | 2000/11 (probably jdk 1.3.1) | 2003/1 (probably jdk 1.3.1) | 2004/10 (jdk1.4.2_03) | 2007/2 (jdk1.6.0_b105) |
---|---|---|---|---|
100,000 regular calls | 2664ms | 281ms | 203ms | 78ms |
100,000 reflection calls without lookup | 4216ms | 297ms | 250ms | 78ms |
100,000 reflection calls with lookup | 45505ms | 938ms | 562ms | 203ms |
1,000,000 regular calls | 27840ms | 2578ms | 1828ms | 594ms |
1,000,000 reflection calls without lookup | 43863ms | 2782ms | 2485ms | 641ms |
1,000,000 reflection calls with lookup | 47097ms | 5453ms | 9343ms | 1984ms |
10,000,000 regular calls | - | 25906ms | 17766ms | 5063ms |
10,000,000 reflection calls without lookup | - | 27891ms | 24813ms | 6141ms |
10,000,000 reflection calls with lookup | - | 54843ms | 93611ms | 20093ms |
Link: What are the performance costs involved in Java reflection? E.g., looking up a method by name and then invoking it.
Comments