s/BenchmarkOutcome.st
changeset 262 8d2849dd3227
parent 142 c69d1eb92d91
child 285 0cf54ee76de5
--- a/s/BenchmarkOutcome.st	Sun Nov 09 18:04:29 2014 +0100
+++ b/s/BenchmarkOutcome.st	Wed Dec 03 23:53:25 2014 +0000
@@ -1,7 +1,7 @@
 "{ Package: 'jv:calipel/s' }"
 
 Object subclass:#BenchmarkOutcome
-	instanceVariableNames:'times benchmark parameters'
+	instanceVariableNames:'measurements benchmark parameters'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'CalipeL-S-Core'
@@ -10,16 +10,10 @@
 
 !BenchmarkOutcome class methodsFor:'instance creation'!
 
-benchmark:benchmarkArg times:timesArg parameters:paramsArg 
-    ^self new benchmark:benchmarkArg times:timesArg parameters:paramsArg
+benchmark: benchmark parameters: parameters measurements: measurements
+    ^ self new benchmark: benchmark parameters: parameters measurements: measurements
 
-    "Created: / 11-06-2013 / 23:19:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-instance:instanceArg times:timesArg parameters:paramsArg 
-    ^self new instance:instanceArg times:timesArg parameters:paramsArg
-
-    "Created: / 04-06-2013 / 22:26:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 24-11-2014 / 06:56:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !BenchmarkOutcome methodsFor:'accessing'!
@@ -30,28 +24,63 @@
     "Created: / 11-06-2013 / 23:19:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+best
+    "Return the best run, i.e., run with minimal time"
+
+    ^ measurements inject: measurements anyOne into:[ :best :each |
+        | bestTime eachTime |
+
+        bestTime := best detect:[:m | BenchmarkMeasurementInstrument isExecuttionTimeInstrument: m instrument ] ifNone:[ nil ].
+        eachTime := best detect:[:m | BenchmarkMeasurementInstrument isExecuttionTimeInstrument: m instrument ] ifNone:[ nil ].
+
+        bestTime notNil ifTrue:[ 
+            eachTime notNil ifTrue:[ 
+                eachTime value < bestTime value ifTrue:[ each ] ifFalse:[ best ]
+            ] ifFalse:[
+                best
+            ]
+        ] ifFalse:[ 
+            eachTime notNil ifTrue:[ each ] ifFalse:[ best ]
+        ].
+    ].
+
+    "Created: / 25-11-2014 / 01:18:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-12-2014 / 23:28:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+measurements
+    ^ measurements
+!
+
 parameters
     ^ parameters
 !
 
 time
-    ^ times min
+    ^ (self times select:[:t | t notNil]) min
 
-    "Modified: / 04-06-2013 / 22:25:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 25-11-2014 / 01:23:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 times
-    ^ times
+    ^ measurements collect:[ :run | 
+        | timeMeasurement |
+
+        timeMeasurement := run detect:[:each | BenchmarkMeasurementInstrument isExecuttionTimeInstrument: each instrument ] ifNone:[ nil ].
+        timeMeasurement value.
+    ]
+
+    "Modified: / 02-12-2014 / 23:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !BenchmarkOutcome methodsFor:'initialization'!
 
-benchmark:benchmarkArg times:timesArg parameters:paramsArg 
+benchmark: benchmarkArg parameters: parametersArg measurements: measurementsArg 
     benchmark := benchmarkArg.
-    times := timesArg.
-    parameters := paramsArg.
+    measurements := measurementsArg.
+    parameters := parametersArg.
 
-    "Created: / 11-06-2013 / 23:19:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 24-11-2014 / 06:56:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !BenchmarkOutcome class methodsFor:'documentation'!