s/BenchmarkResultC.st
changeset 279 af5ed3f190d4
parent 262 8d2849dd3227
child 290 4edd481e1725
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/s/BenchmarkResultC.st	Fri Sep 18 09:21:21 2015 +0100
@@ -0,0 +1,170 @@
+"{ Package: 'jv:calipel/s' }"
+
+"{ NameSpace: Smalltalk }"
+
+Object subclass:#BenchmarkResultC
+	instanceVariableNames:'timestamp outcomes runs'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'CalipeL-S-Core'
+!
+
+
+!BenchmarkResultC class methodsFor:'instance creation'!
+
+new
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
+! !
+
+!BenchmarkResultC methodsFor:'accessing'!
+
+outcomes
+    ^ outcomes
+!
+
+outcomesDo: aBlock
+    "Iterate outcomes, perform given block.
+     outcomes are sorted by benchmark instance name first,
+     then by benchmark name"
+
+    ^self outcomesDo: aBlock separatedBy: nil
+
+    "Created: / 11-06-2013 / 23:11:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+outcomesDo: aBlock separatedBy: anotherBlock
+    "Iterate outcomes, perform given block.
+     outcomes are sorted by benchmark instance name first,
+     then by benchmark name"
+
+    | classes classesOutcomes |
+    classes := SortedCollection sortBlock:[:a :b|a name < b name].
+    classesOutcomes := Dictionary new.
+    outcomes do:[:each|
+        (classes includes: each benchmark instance class) ifFalse:[
+            classes add: each benchmark instance class.
+        ].
+        (classesOutcomes at: each benchmark instance class ifAbsentPut:[SortedCollection sortBlock:[:a :b|a benchmark selector < b benchmark selector]])
+            add: each.
+    ].
+    classes 
+        do:[:class|(classesOutcomes at: class) do: aBlock separatedBy: anotherBlock]
+        separatedBy: anotherBlock
+
+    "Created: / 11-06-2013 / 23:37:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+runs
+    "Return how many times each benchmark is run." 
+
+    ^ runs
+
+    "Modified (format): / 04-06-2013 / 22:25:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+runs:anInteger
+     "Sets how many times each benchmark is run." 
+
+    runs := anInteger.
+
+    "Modified (comment): / 04-06-2013 / 22:25:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+timestamp
+    ^ timestamp
+
+    "Created: / 23-06-2013 / 00:54:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkResultC methodsFor:'adding & removing'!
+
+addOutcome: outcome
+    outcomes add: outcome
+
+    "Created: / 25-07-2013 / 23:53:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkResultC methodsFor:'initialization'!
+
+initialize
+    "Invoked when a new instance is created."
+
+    outcomes := OrderedCollection new.
+    runs := 1.
+
+    "Modified: / 04-06-2013 / 22:23:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+initializeTimestamp
+
+    Smalltalk isSmalltalkX ifTrue:[
+        timestamp := Timestamp now.
+        ^self
+    ].
+    Smalltalk isSqueak ifTrue:[
+        timestamp := DateAndTime now.
+        ^self
+    ].
+    self error: 'Unsupported platform'
+
+    "Created: / 23-06-2013 / 00:39:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+initializeTimestampIfNotAlready
+    timestamp isNil ifTrue:[
+        self initializeTimestamp
+    ]
+
+    "Created: / 23-06-2013 / 00:39:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkResultC methodsFor:'inspecting'!
+
+inspector2TabJSON
+    <inspector2Tab>
+
+    ^ (self newInspector2Tab)
+        label:'JSON report';
+        priority:50;
+        text: [ String streamContents: [:s | BenchmarkReport json write: self on: s ] ];
+        yourself
+
+    "Modified: / 25-11-2014 / 01:07:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+inspector2TabTEXT
+    <inspector2Tab>
+
+    ^ (self newInspector2Tab)
+        label:'Text report';
+        priority:51;
+        text: [ String streamContents: [:s | BenchmarkReport text write: self on: s ] ];
+        yourself
+
+    "Created: / 25-11-2014 / 01:07:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkResultC methodsFor:'printing & storing'!
+
+printOn:aStream
+    "append a printed representation if the receiver to the argument, aStream"
+
+    aStream nextPutAll: 'Benchmark resut:'; cr.
+    BenchmarkReport text write: self on: aStream
+
+    "Modified: / 31-05-2013 / 10:38:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkResultC 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'
+! !
+