11package pl .wavesoftware .eid .exceptions ;
22
3- import org .junit .Before ;
43import org .junit .ClassRule ;
54import org .junit .Test ;
65import org .junit .rules .RuleChain ;
76import org .openjdk .jmh .annotations .Benchmark ;
87import 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 ;
128import org .openjdk .jmh .infra .Blackhole ;
139import org .openjdk .jmh .results .RunResult ;
1410import org .openjdk .jmh .runner .Runner ;
2016import pl .wavesoftware .testing .JavaAgentSkip ;
2117import pl .wavesoftware .testing .JmhCleaner ;
2218
23- import java .text .NumberFormat ;
2419import java .util .Collection ;
2520import java .util .Date ;
2621import java .util .concurrent .TimeUnit ;
@@ -43,26 +38,6 @@ public class EidIT {
4338 .outerRule (new JmhCleaner (EidIT .class ))
4439 .around (JavaAgentSkip .ifActive ());
4540
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-
6641 @ Test
6742 public void doBenckmarking () throws Exception {
6843 Options opt = new OptionsBuilder ()
@@ -78,6 +53,7 @@ public void doBenckmarking() throws Exception {
7853 .forks (1 )
7954 .shouldFailOnError (true )
8055 .shouldDoGC (true )
56+ .jvmArgs ("-server" , "-Xms256m" , "-Xmx256m" , "-XX:PermSize=128m" , "-XX:MaxPermSize=128m" , "-XX:+UseParallelGC" )
8157 .build ();
8258
8359 Runner runner = new Runner (opt );
@@ -98,35 +74,24 @@ public void doBenckmarking() throws Exception {
9874
9975 double eidTimes = eidScore / controlScore ;
10076
101- LOG .info (String .format ("Control sample method time per operation: %.2f µsec" , controlScore ));
102- LOG .info (String .format ("#eid() method time per operation: %.2f µsec" , eidScore ));
77+ LOG .info (String .format ("Control sample method time per operation: %.2f ops / µsec" , controlScore ));
78+ LOG .info (String .format ("#eid() method time per operation: %.2f ops / µsec" , eidScore ));
10379 LOG .info (String .format ("%s and is %.2f%%" , eidTitle , eidTimes * PERCENT ));
10480
10581 assertThat (eidTimes ).as (eidTitle ).isGreaterThanOrEqualTo (SPEED_THRESHOLD );
10682 }
10783
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-
11984 @ Benchmark
120- public void control (MemoryState state , Blackhole bh ) {
85+ public void control (Blackhole bh ) {
12186 for (int i = 0 ; i < OPERATIONS ; i ++) {
12287 bh .consume (new Date ());
12388 }
12489 }
12590
12691 @ Benchmark
127- public void eid (MemoryState state , Blackhole bh ) {
92+ public void eid (Blackhole bh ) {
12893 for (int i = 0 ; i < OPERATIONS ; i ++) {
129- bh .consume (new Eid (state . eid ));
94+ bh .consume (new Eid ("20160330:144947" ));
13095 }
13196 }
13297
0 commit comments