s/BenchmarkReportText.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 05 Jun 2013 10:45:29 +0100
changeset 6 25b264cec44e
parent 5 8669edf62d9b
child 12 3a7ebd3da52f
permissions -rw-r--r--
Added parameter to BenchmarkResult to run each benchmark multiple times. The BenchmarkOutcome keeps all times. Also, BenchmarkInstance>>benchmark renamed to selector.

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

BenchmarkReport subclass:#BenchmarkReportText
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'CalipeL/S-Core-Reports'
!


!BenchmarkReportText methodsFor:'formatting'!

format: anObject width: width align: align
    | string |

    string := anObject printString. 
    align == #left ifTrue:[
        stream nextPutAll: string.
        stream next: ((width - string size) max: 0) put: Character space.
        ^self.
    ].
    align == #right ifTrue:[
        stream next: ((width - string size) max: 0) put: Character space.
        stream nextPutAll: string.
        ^self.
    ].
    align == #center ifTrue:[
        stream next: (((width - string size) max: 0) / 2 floor) put: Character space.
        stream nextPutAll: string.
        stream next: (((width - string size) max: 0) / 2 ceiling) put: Character space.
        ^self.
    ]

    "Created: / 31-05-2013 / 12:09:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BenchmarkReportText methodsFor:'writing'!

write
    | classes outcomes |

    classes := SortedCollection sortBlock:[:a :b|a name < b name].
    outcomes := Dictionary new.
    result outcomes do:[:each|
        (classes includes: each instance class) ifFalse:[
            classes add: each instance class.
        ].
        (outcomes at: each instance class ifAbsentPut:[SortedCollection sortBlock:[:a :b|a instance selector < b instance selector]])
            add: each.
    ].

    classes do:[:class|
        stream nextPutAll: '== '; nextPutAll:  class name; nextPutAll: ' =='; cr.
        (outcomes at: class) do:[:outcome|
            self format: outcome instance selector width: 15 align: #right.
            stream nextPutAll: ' : '.
            self format: outcome time width: 5 align: #right.
            stream nextPutAll: ' [ms]'.
            stream cr.
        ].
    ].
    stream cr.

    "Modified: / 31-05-2013 / 12:11:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BenchmarkReportText 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'
! !