-1

I heard that cglib takes less time as compare to java reflection for runtime object creation but when I checked, it is taking 100 times more time than java reflection.
Following is the result of my research

Creating 10000 objects

CGLIB:191 milliseconds
Normal:2 milliseconds
Reflection:24 milliseconds

I want to ask here that what are the benefits of using cglib/javaassit over java reflection.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
zubair
  • 185
  • 3
  • 15
  • 1
    Benchmarks are hard to get right. The JVM uses code generation to make reflection as fast as native invocation but primitive types might be boxed what takes ressources. Code generation is used when needing to retain type-safety. – Rafael Winterhalter Jan 22 '15 at 06:41

1 Answers1

1

I have found the benefits of cglib over Java reflection. Class generated using runtime byte-code generation library (cglib, javassit, byte buddy) can be altered at runtime without recompiling and Java Reflection classes can't be altered.

zubair
  • 185
  • 3
  • 15