-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHibernateBenchmark.java
76 lines (59 loc) · 2.14 KB
/
HibernateBenchmark.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package demo;
import java.util.Collection;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import demo.domain.AuthorWithBooks;
import demo.service.AuthorQueries;
/**
* Created by nlabrot on 10/10/15.
*/
public class HibernateBenchmark {
@State(Scope.Benchmark)
public static class BenchmarkSpringState {
private ConfigurableApplicationContext configurableApplicationContext;
private AuthorQueries authorQueries;
@Setup(Level.Trial)
public void init() {
configurableApplicationContext = SpringApplication.run(Application.class);
authorQueries = configurableApplicationContext.getBean(AuthorQueries.class);
}
public AuthorQueries getAuthorQueries() {
return authorQueries;
}
}
@Benchmark
public Collection<AuthorWithBooks> findAuthorsWithBooksUsingCriteria(BenchmarkSpringState state) {
return state.getAuthorQueries().findAuthorsWithBooksUsingCriteria();
}
@Benchmark
public Collection<AuthorWithBooks> findAuthorsWithBooksUsingNamedQuery(BenchmarkSpringState state) {
return state.getAuthorQueries().findAuthorsWithBooksUsingNamedQuery();
}
@Benchmark
public Collection<AuthorWithBooks> findAuthorsWithBooksUsingSpringData(BenchmarkSpringState state) {
return state.getAuthorQueries().findAuthorsWithBooksUsingSpringData();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(HibernateBenchmark.class.getSimpleName())
.warmupIterations(5)
.warmupTime(TimeValue.seconds(5))
.measurementIterations(5)
.measurementTime(TimeValue.seconds(5))
.threads(1)
.forks(1)
.jvmArgs("-Xmx1g")
.build();
new Runner(opt).run();
}
}