11package pl .wavesoftware .eid .exceptions ;
22
3+ import org .junit .Before ;
34import org .junit .ClassRule ;
45import org .junit .Test ;
56import org .junit .rules .RuleChain ;
67import org .openjdk .jmh .annotations .Benchmark ;
78import org .openjdk .jmh .annotations .Mode ;
9+ import org .openjdk .jmh .annotations .Scope ;
10+ import org .openjdk .jmh .annotations .Setup ;
11+ import org .openjdk .jmh .annotations .State ;
812import org .openjdk .jmh .infra .Blackhole ;
913import org .openjdk .jmh .results .RunResult ;
1014import org .openjdk .jmh .runner .Runner ;
1620import pl .wavesoftware .testing .JavaAgentSkip ;
1721import pl .wavesoftware .testing .JmhCleaner ;
1822
23+ import java .text .NumberFormat ;
1924import java .util .Collection ;
2025import java .util .Date ;
2126import java .util .concurrent .TimeUnit ;
@@ -38,6 +43,26 @@ public class EidIT {
3843 .outerRule (new JmhCleaner (EidIT .class ))
3944 .around (JavaAgentSkip .ifActive ());
4045
46+ @ Before
47+ public void before () {
48+ printMemory ();
49+ }
50+
51+ public static void printMemory () {
52+ Runtime runtime = Runtime .getRuntime ();
53+
54+ NumberFormat format = NumberFormat .getInstance ();
55+
56+ long maxMemory = runtime .maxMemory ();
57+ long allocatedMemory = runtime .totalMemory ();
58+ long freeMemory = runtime .freeMemory ();
59+
60+ LOG .info ("free memory: {} KiB" , format .format (freeMemory / 1024 ));
61+ LOG .info ("allocated memory: {} KiB" , format .format (allocatedMemory / 1024 ));
62+ LOG .info ("max memory: {} KiB" , format .format (maxMemory / 1024 ));
63+ LOG .info ("total free memory: {} KiB" , format .format ((freeMemory + (maxMemory - allocatedMemory )) / 1024 ));
64+ }
65+
4166 @ Test
4267 public void doBenckmarking () throws Exception {
4368 Options opt = new OptionsBuilder ()
@@ -69,7 +94,7 @@ public void doBenckmarking() throws Exception {
6994
7095 String title = "method speed quotient to the control sample" ;
7196 String eidTitle = String .format ("%s %s should be at least %.2f%%" , "#eid()" ,
72- title , SPEED_THRESHOLD * PERCENT );
97+ title , SPEED_THRESHOLD * PERCENT );
7398
7499 double eidTimes = eidScore / controlScore ;
75100
@@ -80,17 +105,28 @@ public void doBenckmarking() throws Exception {
80105 assertThat (eidTimes ).as (eidTitle ).isGreaterThanOrEqualTo (SPEED_THRESHOLD );
81106 }
82107
108+ @ State (Scope .Benchmark )
109+ public static class MemoryState {
110+ private String eid ;
111+
112+ @ Setup
113+ public void setup () {
114+ printMemory ();
115+ this .eid = "20160330:124244" ;
116+ }
117+ }
118+
83119 @ Benchmark
84- public void control (Blackhole bh ) {
120+ public void control (MemoryState state , Blackhole bh ) {
85121 for (int i = 0 ; i < OPERATIONS ; i ++) {
86122 bh .consume (new Date ());
87123 }
88124 }
89125
90126 @ Benchmark
91- public void eid (Blackhole bh ) {
127+ public void eid (MemoryState state , Blackhole bh ) {
92128 for (int i = 0 ; i < OPERATIONS ; i ++) {
93- bh .consume (new Eid ("20160324:223837" ));
129+ bh .consume (new Eid (state . eid ));
94130 }
95131 }
96132
0 commit comments