1010import org .openjdk .jmh .runner .options .Options ;
1111import org .openjdk .jmh .runner .options .OptionsBuilder ;
1212import org .openjdk .jmh .runner .options .TimeValue ;
13+ import org .slf4j .Logger ;
14+ import org .slf4j .LoggerFactory ;
1315
1416import java .util .Collection ;
1517import java .util .Date ;
2426public class EidIT {
2527
2628 private static final int OPERATIONS = 1000 ;
29+ private static final Logger LOG = LoggerFactory .getLogger (EidIT .class );
30+ private static final double SPEED_THRESHOLD = 0.75d ;
31+ public static final int PERCENT = 100 ;
2732
2833 @ Test
2934 public void doBenckmarking () throws Exception {
@@ -45,6 +50,26 @@ public void doBenckmarking() throws Exception {
4550 Runner runner = new Runner (opt );
4651 Collection <RunResult > results = runner .run ();
4752 assertThat (results ).hasSize (2 );
53+
54+ RunResult control = getRunResultByName (results , "control" );
55+ RunResult eid = getRunResultByName (results , "eid" );
56+ assertThat (control ).isNotNull ();
57+ assertThat (eid ).isNotNull ();
58+
59+ double controlScore = control .getAggregatedResult ().getPrimaryResult ().getScore ();
60+ double eidScore = eid .getAggregatedResult ().getPrimaryResult ().getScore ();
61+
62+ String title = "method speed quotient to the control sample" ;
63+ String eidTitle = String .format ("%s %s should be at least %.2f%%" , "#exhibit()" ,
64+ title , SPEED_THRESHOLD * PERCENT );
65+
66+ double eidTimes = eidScore / controlScore ;
67+
68+ LOG .info (String .format ("Control sample method time per operation: %.2f µsec" , controlScore ));
69+ LOG .info (String .format ("#eid() method time per operation: %.2f µsec" , eidScore ));
70+ LOG .info (String .format ("%s and is %.2f%%" , eidTitle , eidTimes * PERCENT ));
71+
72+ assertThat (eidTimes ).as (eidTitle ).isGreaterThanOrEqualTo (SPEED_THRESHOLD );
4873 }
4974
5075 @ Benchmark
@@ -60,4 +85,14 @@ public void eid(Blackhole bh) {
6085 bh .consume (new Eid ("20160324:223837" ));
6186 }
6287 }
88+
89+ private static RunResult getRunResultByName (Collection <RunResult > results , String name ) {
90+ String fullName = String .format ("%s.%s" , EidIT .class .getName (), name );
91+ for (RunResult result : results ) {
92+ if (result .getParams ().getBenchmark ().equals (fullName )) {
93+ return result ;
94+ }
95+ }
96+ throw new EidRuntimeException ("20160324:225412" , "Invalid name: " + name );
97+ }
6398}
0 commit comments