s/BenchmarkOutcome.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 03 Dec 2014 23:53:25 +0000
changeset 262 8d2849dd3227
parent 142 c69d1eb92d91
child 285 0cf54ee76de5
permissions -rw-r--r--
Added support for (user-defined) benchmark instruments. * Introduced `BenchmarkMeasurementInstrument`, an abstraction to allow pluggin in a different aspects to measure - execution time, number scavenges, number fo full GC's... * Introduced `BenchmarkMeasurement`, a value object that holds a result of measurement done by a single `BenchmarkMeasurementInstrument`. * Code refactored so now `BenchmarkOutcome` now keeps a set of `BenchmarkMeasure`s * Measurements from each instrument are in reports. JSON report keep 'times' array for backward compatibility. * Each platform may define it's set of intruments that is used by default and __ALWAYS__. They should be non-intrusive. * Added command line option `-i` / `--instrument` to specify user-defined instrument to use. *

"{ Package: 'jv:calipel/s' }"

Object subclass:#BenchmarkOutcome
	instanceVariableNames:'measurements benchmark parameters'
	classVariableNames:''
	poolDictionaries:''
	category:'CalipeL-S-Core'
!


!BenchmarkOutcome class methodsFor:'instance creation'!

benchmark: benchmark parameters: parameters measurements: measurements
    ^ self new benchmark: benchmark parameters: parameters measurements: measurements

    "Created: / 24-11-2014 / 06:56:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BenchmarkOutcome methodsFor:'accessing'!

benchmark
    ^ benchmark

    "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
    ^ (self times select:[:t | t notNil]) min

    "Modified (format): / 25-11-2014 / 01:23:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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 parameters: parametersArg measurements: measurementsArg 
    benchmark := benchmarkArg.
    measurements := measurementsArg.
    parameters := parametersArg.

    "Created: / 24-11-2014 / 06:56:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BenchmarkOutcome class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_MC
    ^ 'CalipeL_S-Core-JanVrany.7 5c300a20-c9d7-11e2-a959-606720e43e2c 2013-05-31T10:49:17 JanVrany'
! !