Skip to end of metadata
Go to start of metadata

In this article you will see a simple performance test on the simplest use of Spring and Nuts.

We will compare simple bean without injection, constructor injection, setter injection, singleton bean, prototype bean and spring aop interceptor.

All Spring test cases repeatedly call "getBean()" hundreds of thousands of times against a Spring XMLBeanFactory object. Since Yan provides a "getFactory()" method that's useful when the same Factory object is used multiple times, we'll call "getInstance()" and "getFactory()" in different test cases.

To give you a quick sense of the test case, the Spring test cases all look like:

While the Nuts test cases are like:

The Nuts test cases calling "getFactory()" are:

Since Nuts doesn't provide an out-of-the-box AOP solution (we don't want to re-invent wheels unless necessary), Spring is integrated into Nuts to get the test data on AOP. Therefore, we have a seperate set of test cases for Nuts performance when Spring is integrated.

This benchmark is by no means complete nor 100% accurate. I'm no expert on software benchmarking. My laptop is slow and short of memory (only 1G). Lots of advanced features of Spring and Nuts are not covered. The test models are also very simple in the sense that not too many dependencies need to be injected.

And here goes the test result:

Speed Comparison (calls/sec)  


Nuts w/o Spring Integration 

Nuts with Spring Integration 

 no dependency injection


 689,655 (28 times)  

 433,839 (18 times)

 Constructor Injection


 298,062 (29 times)  

 212,539 (20 times)

 Setter Injection  


 172,117 (14 times)  

 117,508 (9 times)

 getFactory() for Constructor Injection


 327,332 (32 times)  

 201,612 (16 times)

 getFactory() for Setter Injection  


 197,823 (16 times)  

 127,959 (10 times)

 autowire bytype Setter Injection  


 120,992 (15 times)  

 90,785 (11 times)

 singleton bean  


 6,060,606 (3 times)  

 6,042,296 (3 times)

 getFactory() for singleton  


 18,181,818 (9 times)

 20,000,000 (10 times)

 client defined factory interface for singleton  


 10,000,000 (5 times)

 10,526,315 (5 times)

 Bean method invocation with noop interceptor applied



 2,531,004 (0.86 times)

 Creating bean with interceptor applied



 1688 (0.9 times)

For Nuts speed, in addition to the "call per sec" number, we also give the ratio of Nuts speed to the Spring speed.

This test is based on the Spring version 1.2.6. (We did a comparison on Spring 1.1.4 as well, 1.1.4 appeared to be a bit faster than 1.2.6.)

As you can see, Nuts Spring Integration performs a bit slower for Spring AOP than Spring. Other than that, Nuts is faster than Spring (with or without Spring Integration) in all other test cases. The ratio ranges from 3 times to 29 times faster.

The following are the test cases:

  • No labels