Skip to content

Commit

Permalink
adding classic Spring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Mar 31, 2018
1 parent 4a67339 commit 8946080
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# DI Containers Comparision

Comparing a simple app written with Cayenne DI, Dagger 2,
Guice and SpringBoot.
Comparing a simple app varieties on different DI containers.

## IntelliJ IDEA Setup

Expand All @@ -11,23 +10,30 @@ Processing".
## "Benchmark"

```
# Warmup build
$ mvn clean package
# Measure assembly time with "-o" to ensure loading dependencies over
# the network does not interfere...
$ mvn clean package -o
# Get the file sizes
$ find . -name '*.jar' |xargs ls -l |grep -v original |grep -v common
# Execution time
$ time java -jar ./cayennedi/target/cayennedi-1.0-SNAPSHOT.jar
$ time java -jar ./dagger/target/dagger-1.0-SNAPSHOT.jar
$ time java -jar ./guice/target/guice-1.0-SNAPSHOT.jar
$ time java -jar ./spring/target/spring-1.0-SNAPSHOT.jar
$ time java -jar ./springboot/target/springboot-1.0-SNAPSHOT.jar
```

## Results

|DI|Compile/Package Time, ms|Jar with Dependencies, KB|Exec time, ms|
|----|-----|-----|----|
|Dagger|1320|51|122|
|Cayenne DI|93|79|166|
|Guice|483|3440|353|
|Spring Boot|527|6993|1628|
|Dagger|1297|51|121|
|Cayenne DI|91|79|180|
|Guice|477|3440|358|
|Spring|468|3545|506|
|Spring Boot|441|6993|1549|
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<dagger.version>2.15</dagger.version>
<guice.version>4.2.0</guice.version>
<cayenne.version>4.0.B2</cayenne.version>
<spring.version>5.0.3.RELEASE</spring.version>
<springboot.version>2.0.0.RELEASE</springboot.version>
</properties>

Expand All @@ -25,6 +26,7 @@
<module>dagger</module>
<module>guice</module>
<module>cayennedi</module>
<module>spring</module>
<module>springboot</module>
</modules>

Expand Down
43 changes: 43 additions & 0 deletions spring/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.objectstyle.di</groupId>
<artifactId>di-comparison</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>spring</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>jar</packaging>

<properties>
<main.class>org.objectstyle.spring.Main</main.class>
</properties>

<dependencies>
<dependency>
<groupId>org.objectstyle.di</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
28 changes: 28 additions & 0 deletions spring/src/main/java/org/objectstyle/spring/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.objectstyle.spring;

import org.objectstyle.di.service.Service;
import org.objectstyle.di.service.ServiceImpl;
import org.objectstyle.di.service.SubService;
import org.objectstyle.di.service.SubServiceImpl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class Main {

@Bean
public Service service(SubService subService) {
return new ServiceImpl(subService);
}

@Bean
public SubService subService() {
return new SubServiceImpl();
}

public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Main.class);
System.out.println(context.getBean(Service.class).doIt());
}
}

0 comments on commit 8946080

Please sign in to comment.