Thursday, July 17, 2008

Reflection is expensive? Illusion!

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.

Operation2000/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 calls2664ms281ms203ms78ms
100,000 reflection calls without lookup4216ms297ms250ms78ms
100,000 reflection calls with lookup45505ms938ms562ms203ms
1,000,000 regular calls27840ms2578ms1828ms594ms
1,000,000 reflection calls without lookup43863ms2782ms2485ms641ms
1,000,000 reflection calls with lookup47097ms5453ms9343ms1984ms
10,000,000 regular calls-25906ms17766ms5063ms
10,000,000 reflection calls without lookup-27891ms24813ms6141ms
10,000,000 reflection calls with lookup-54843ms93611ms20093ms

Link: What are the performance costs involved in Java reflection? E.g., looking up a method by name and then invoking it.
Post a Comment