Added parameter to BenchmarkResult to run each benchmark multiple times.
The BenchmarkOutcome keeps all times. Also, BenchmarkInstance>>benchmark
renamed to selector.
--- a/s/BenchmarkInstance.st Fri May 31 12:13:11 2013 +0100
+++ b/s/BenchmarkInstance.st Wed Jun 05 10:45:29 2013 +0100
@@ -12,8 +12,8 @@
!BenchmarkInstance class methodsFor:'instance creation'!
-class: class benchmark: benchmark
- ^self new class: class benchmark: benchmark
+class:class selector:benchmark
+ ^ self new class:class selector:benchmark
"Created: / 27-05-2013 / 19:04:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
@@ -44,103 +44,105 @@
!BenchmarkInstance methodsFor:'accessing'!
-benchmark
- ^ benchmarkSelector
+instance
+ ^ instance
!
-instance
- ^ instance
+selector
+ ^ benchmarkSelector
! !
!BenchmarkInstance methodsFor:'initialization'!
-class: class benchmark: benchmark
- self instance: class new benchmark: benchmark
+class:class selector:benchmark
+ self instance:class new selector:benchmark
"Created: / 27-05-2013 / 19:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-instance: anObject benchmark: aSelector
- | benchmarkMethod annotation |
- (anObject respondsTo: aSelector) ifFalse:[
- self error:'Object does not respond to benchmark (no ', anObject class printString , '>>', aSelector storeString.
+instance:anObject selector:aSelector
+ | benchmarkMethod annotation |
+
+ (anObject respondsTo:aSelector) ifFalse:[
+ self
+ error:'Object does not respond to benchmark (no '
+ , anObject class printString , '>>'
+ , aSelector storeString.
].
-
instance := anObject.
benchmarkSelector := aSelector.
-
- instance class methodDictionary keysAndValuesDo:[:selector :method |
- method numArgs == 0 ifTrue:[
- (method pragmaAt: #setup) notNil ifTrue:[
- setUpSelector1 notNil ifTrue:[
- self error: 'More than one <setup> method'.
+ instance class methodDictionary
+ keysAndValuesDo:[:selector :method |
+ method numArgs == 0 ifTrue:[
+ (method pragmaAt:#setup) notNil ifTrue:[
+ setUpSelector1 notNil ifTrue:[
+ self error:'More than one <setup> method'.
+ ].
+ setUpSelector1 := selector.
].
- setUpSelector1 := selector.
- ].
- (method pragmaAt: #teardown) notNil ifTrue:[
- tearDownSelector1 notNil ifTrue:[
- self error: 'More than one <teardown> method'.
+ (method pragmaAt:#teardown) notNil ifTrue:[
+ tearDownSelector1 notNil ifTrue:[
+ self error:'More than one <teardown> method'.
+ ].
+ tearDownSelector1 := selector.
].
- tearDownSelector1 := selector.
- ].
- (method pragmaAt: #warmup) notNil ifTrue:[
- warmUpSelector1 notNil ifTrue:[
- self error: 'More than one <warmup> method'.
+ (method pragmaAt:#warmup) notNil ifTrue:[
+ warmUpSelector1 notNil ifTrue:[
+ self error:'More than one <warmup> method'.
+ ].
+ warmUpSelector1 := selector.
].
- warmUpSelector1 := selector.
].
].
- ].
-
- benchmarkMethod := instance class compiledMethodAt: benchmarkSelector.
-
- annotation := benchmarkMethod pragmaAt: #setup:.
+ benchmarkMethod := instance class compiledMethodAt:benchmarkSelector.
+ annotation := benchmarkMethod pragmaAt:#setup:.
annotation notNil ifTrue:[
- | method selector |
- selector := annotation argumentAt: 1.
+ | method selector |
+
+ selector := annotation argumentAt:1.
selector isSymbol ifFalse:[
- self error: '<setup:> annotation argument not a symbol'.
+ self error:'<setup:> annotation argument not a symbol'.
].
- method := instance compiledMethodAt: selector ifAbsent: [nil].
+ method := instance compiledMethodAt:selector ifAbsent:[ nil ].
method isNil ifTrue:[
- self error: '<setup:> method does not exist (', selector,')'.
+ self error:'<setup:> method does not exist (' , selector , ')'.
].
method numArgs ~~ 0 ifTrue:[
- self error: '<setup:> method has arguments (', selector,')'.
+ self error:'<setup:> method has arguments (' , selector , ')'.
].
setUpSelector2 := selector.
].
-
- annotation := benchmarkMethod pragmaAt: #teardown:.
+ annotation := benchmarkMethod pragmaAt:#teardown:.
annotation notNil ifTrue:[
- | method selector |
- selector := annotation argumentAt: 1.
+ | method selector |
+
+ selector := annotation argumentAt:1.
selector isSymbol ifFalse:[
- self error: '<teardown:> annotation argument not a symbol'.
+ self error:'<teardown:> annotation argument not a symbol'.
].
- method := instance compiledMethodAt: selector ifAbsent: [nil].
+ method := instance compiledMethodAt:selector ifAbsent:[ nil ].
method isNil ifTrue:[
- self error: '<teardown:> method does not exist (', selector,')'.
+ self error:'<teardown:> method does not exist (' , selector , ')'.
].
method numArgs ~~ 0 ifTrue:[
- self error: '<teardown:> method has arguments (', selector,')'.
+ self error:'<teardown:> method has arguments (' , selector , ')'.
].
tearDownSelector2 := selector.
].
-
- annotation := benchmarkMethod pragmaAt: #warmup:.
+ annotation := benchmarkMethod pragmaAt:#warmup:.
annotation notNil ifTrue:[
- | method selector |
- selector := annotation argumentAt: 1.
+ | method selector |
+
+ selector := annotation argumentAt:1.
selector isSymbol ifFalse:[
- self error: '<warmup:> annotation argument not a symbol'.
+ self error:'<warmup:> annotation argument not a symbol'.
].
- method := instance compiledMethodAt: selector ifAbsent: [nil].
+ method := instance compiledMethodAt:selector ifAbsent:[ nil ].
method isNil ifTrue:[
- self error: '<warmup:> method does not exist (', selector,')'.
+ self error:'<warmup:> method does not exist (' , selector , ')'.
].
method numArgs ~~ 0 ifTrue:[
- self error: '<warmup:> method has arguments (', selector,')'.
+ self error:'<warmup:> method has arguments (' , selector , ')'.
].
warmUpSelector2 := selector.
].
@@ -179,7 +181,7 @@
self setUp.
self setUpParameters:aBenchmarkParameterSet.
self warmUp.
- t := self performBenchmark.
+ t := self benchmark.
] ensure:[ self tearDown. ].
^ t
@@ -195,23 +197,18 @@
!BenchmarkInstance methodsFor:'running-private'!
-performBenchmark
- | t0 t1 |
+benchmark
+ | t0 t1 |
t0 := MillisecondsTime value.
- instance perform: benchmarkSelector.
+ instance perform:benchmarkSelector.
t1 := MillisecondsTime value.
- ^t1 - t0
+ ^ t1 - t0
"Created: / 28-05-2013 / 08:49:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 31-05-2013 / 12:02:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-performSetUpAnnotatedBy: keyword
-
- "Created: / 28-05-2013 / 08:51:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
setUp
setUpSelector1 notNil ifTrue:[
instance perform: setUpSelector1
@@ -299,10 +296,10 @@
warmed ifFalse:[
instance perform: benchmarkSelector
].
+ ObjectMemory garbageCollect; tenure.
"Created: / 27-05-2013 / 19:02:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 28-05-2013 / 11:00:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (comment): / 31-05-2013 / 00:30:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-06-2013 / 22:19:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkInstance class methodsFor:'documentation'!
--- a/s/BenchmarkOutcome.st Fri May 31 12:13:11 2013 +0100
+++ b/s/BenchmarkOutcome.st Wed Jun 05 10:45:29 2013 +0100
@@ -1,7 +1,7 @@
"{ Package: 'jv:calipel/s' }"
Object subclass:#BenchmarkOutcome
- instanceVariableNames:'instance time params'
+ instanceVariableNames:'instance params times'
classVariableNames:''
poolDictionaries:''
category:'CalipeL/S-Core'
@@ -10,10 +10,10 @@
!BenchmarkOutcome class methodsFor:'instance creation'!
-instance:instanceArg time:timeArg parameters:paramsArg
- ^self new instance:instanceArg time:timeArg parameters:paramsArg
+instance:instanceArg times:timesArg parameters:paramsArg
+ ^self new instance:instanceArg times:timesArg parameters:paramsArg
- "Created: / 27-05-2013 / 22:24:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 04-06-2013 / 22:26:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkOutcome methodsFor:'accessing'!
@@ -27,17 +27,23 @@
!
time
- ^ time
+ ^ times min
+
+ "Modified: / 04-06-2013 / 22:25:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+times
+ ^ times
! !
!BenchmarkOutcome methodsFor:'initialization'!
-instance:instanceArg time:timeArg parameters:paramsArg
+instance:instanceArg times:timesArg parameters:paramsArg
instance := instanceArg.
- time := timeArg.
+ times := timesArg.
params := paramsArg.
- "Created: / 27-05-2013 / 22:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 04-06-2013 / 22:26:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkOutcome class methodsFor:'documentation'!
--- a/s/BenchmarkReportText.st Fri May 31 12:13:11 2013 +0100
+++ b/s/BenchmarkReportText.st Wed Jun 05 10:45:29 2013 +0100
@@ -45,14 +45,14 @@
(classes includes: each instance class) ifFalse:[
classes add: each instance class.
].
- (outcomes at: each instance class ifAbsentPut:[SortedCollection sortBlock:[:a :b|a instance benchmark < b instance benchmark]])
+ (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 benchmark width: 15 align: #right.
+ self format: outcome instance selector width: 15 align: #right.
stream nextPutAll: ' : '.
self format: outcome time width: 5 align: #right.
stream nextPutAll: ' [ms]'.
--- a/s/BenchmarkResult.st Fri May 31 12:13:11 2013 +0100
+++ b/s/BenchmarkResult.st Wed Jun 05 10:45:29 2013 +0100
@@ -1,7 +1,7 @@
"{ Package: 'jv:calipel/s' }"
Object subclass:#BenchmarkResult
- instanceVariableNames:'outcomes'
+ instanceVariableNames:'outcomes runs'
classVariableNames:''
poolDictionaries:''
category:'CalipeL/S-Core'
@@ -20,6 +20,22 @@
outcomes
^ outcomes
+!
+
+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>"
! !
!BenchmarkResult methodsFor:'initialization'!
@@ -28,9 +44,9 @@
"Invoked when a new instance is created."
outcomes := Set new.
+ runs := 1.
- "Modified: / 27-05-2013 / 18:57:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (comment): / 31-05-2013 / 00:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-06-2013 / 22:23:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkResult methodsFor:'printing & storing'!
@@ -46,23 +62,18 @@
!BenchmarkResult methodsFor:'running-private'!
-performBenchmark:aBenchmarkInstance withParameters:aDictionary
- ^aBenchmarkInstance runBenchmarkWithParameters:aDictionary
+runBenchmark:aBenchmarkInstance withParameters: aDictionary
+ | times |
- "Created: / 27-05-2013 / 22:24:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-runBenchmark:aBenchmarkInstance withParameters: aDictionary
- | time |
-
- time := self performBenchmark: aBenchmarkInstance withParameters:aDictionary.
+ times := (1 to: runs) collect: [:i | aBenchmarkInstance runBenchmarkWithParameters: aDictionary].
outcomes add:
(BenchmarkOutcome
instance: aBenchmarkInstance
- time: time
+ times: times
parameters: aBenchmarkInstance)
"Created: / 27-05-2013 / 22:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 05-06-2013 / 10:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkResult class methodsFor:'documentation'!
--- a/s/BenchmarkSuite.st Fri May 31 12:13:11 2013 +0100
+++ b/s/BenchmarkSuite.st Wed Jun 05 10:45:29 2013 +0100
@@ -18,7 +18,7 @@
[ current notNil ] whileTrue:[
current selectorsAndMethodsDo:[:selector :method|
(method pragmaAt:#benchmark) notNil ifTrue:[
- suite addBenchmark: (BenchmarkInstance class: class benchmark: selector)
+ suite addBenchmark: (BenchmarkInstance class:class selector:selector)
].
].
current := current superclass.
@@ -28,8 +28,8 @@
"Created: / 28-05-2013 / 19:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-class: class benchmark: benchmark
- ^BenchmarkInstance class: class benchmark: benchmark
+class:class selector:benchmark
+ ^ BenchmarkInstance class:class selector:benchmark
"Created: / 28-05-2013 / 19:46:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
--- a/s/benchmarks/BenchmarkGame.st Fri May 31 12:13:11 2013 +0100
+++ b/s/benchmarks/BenchmarkGame.st Wed Jun 05 10:45:29 2013 +0100
@@ -11,7 +11,7 @@
!BenchmarkGame class methodsFor:'running'!
run: benchmark
- ^ (BenchmarkInstance class: BenchmarkGame benchmark: #strcat) run
+ ^ (BenchmarkInstance class:BenchmarkGame selector:#strcat) run
"Created: / 31-05-2013 / 10:39:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
--- a/s/benchmarks/benchmarks.rc Fri May 31 12:13:11 2013 +0100
+++ b/s/benchmarks/benchmarks.rc Wed Jun 05 10:45:29 2013 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.3.0\0"
- VALUE "ProductDate", "Fri, 31 May 2013 10:50:40 GMT\0"
+ VALUE "ProductDate", "Wed, 05 Jun 2013 09:43:06 GMT\0"
END
END
--- a/s/s.rc Fri May 31 12:13:11 2013 +0100
+++ b/s/s.rc Wed Jun 05 10:45:29 2013 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.3.0\0"
- VALUE "ProductDate", "Fri, 31 May 2013 11:11:39 GMT\0"
+ VALUE "ProductDate", "Wed, 05 Jun 2013 09:43:19 GMT\0"
END
END
--- a/s/stx/BenchmarkRunner.st Fri May 31 12:13:11 2013 +0100
+++ b/s/stx/BenchmarkRunner.st Wed Jun 05 10:45:29 2013 +0100
@@ -214,7 +214,7 @@
selector isNil ifTrue:[
suite addBenchmark: (BenchmarkSuite class: class)
] ifFalse:[
- suite addBenchmark: (BenchmarkSuite class: class benchmark: selector)
+ suite addBenchmark: (BenchmarkSuite class:class selector:selector)
]
].
--- a/s/stx/stx.rc Fri May 31 12:13:11 2013 +0100
+++ b/s/stx/stx.rc Wed Jun 05 10:45:29 2013 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.3.0\0"
- VALUE "ProductDate", "Tue, 28 May 2013 19:23:21 GMT\0"
+ VALUE "ProductDate", "Wed, 05 Jun 2013 09:43:00 GMT\0"
END
END
--- a/s/tests/BenchmarkInstanceTests.st Fri May 31 12:13:11 2013 +0100
+++ b/s/tests/BenchmarkInstanceTests.st Wed Jun 05 10:45:29 2013 +0100
@@ -74,7 +74,7 @@
| b r |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
r := b run.
self assert: r outcomes size == 1.
@@ -88,7 +88,7 @@
test_02
self
- should: [BenchmarkInstance class: self class benchmark: #non_existent_benchmark]
+ should: [BenchmarkInstance class:self class selector:#'non_existent_benchmark']
raise: Error
"Created: / 27-05-2013 / 22:13:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -98,7 +98,7 @@
| b r |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
r := b runWith: Dictionary new.
self assert: param1 isNil
@@ -110,7 +110,7 @@
| b r |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
r := b runWith: (Dictionary new at: #param1 put: '1234'; yourself).
self assert: param1 == 1234
@@ -122,7 +122,7 @@
| b r |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
r := b runWith: (Dictionary new at: #'BenchmarkInstanceTests#param1' put: '1234'; yourself).
self assert: param1 == 1234
@@ -134,7 +134,7 @@
| b r |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
r := b runWith: (Dictionary new
at: #'param1' put: '9876';
at: #'BenchmarkInstanceTests#param1' put: '1234'; yourself).
@@ -148,7 +148,7 @@
| b |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
self should: [
b runWith: (Dictionary new
at: #'param2' put: '5555'; yourself).
@@ -161,7 +161,7 @@
| b |
- b := BenchmarkInstance new instance: self benchmark: #bench_01.
+ b := BenchmarkInstance new instance:self selector:#'bench_01'.
self should: [
b runWith: (Dictionary new
at: #'param1' put: 'asdf'; yourself).
--- a/s/tests/Make.proto Fri May 31 12:13:11 2013 +0100
+++ b/s/tests/Make.proto Wed Jun 05 10:45:29 2013 +0100
@@ -102,6 +102,7 @@
# build all mandatory prerequisite packages (containing superclasses) for this package
prereq:
cd $(TOP)/libbasic && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
+ cd $(TOP)/libbasic2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
cd $(TOP)/libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
cd $(TOP)/libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
cd $(TOP)/goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
--- a/s/tests/bc.mak Fri May 31 12:13:11 2013 +0100
+++ b/s/tests/bc.mak Wed Jun 05 10:45:29 2013 +0100
@@ -51,6 +51,7 @@
# build all mandatory prerequisite packages (containing superclasses) for this package
prereq:
pushd ..\..\..\..\stx\libbasic & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
+ pushd ..\..\..\..\stx\libbasic2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
pushd ..\..\..\..\stx\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
pushd ..\..\..\..\stx\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
pushd ..\..\..\..\stx\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
--- a/s/tests/tests.rc Fri May 31 12:13:11 2013 +0100
+++ b/s/tests/tests.rc Wed Jun 05 10:45:29 2013 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.3.0\0"
- VALUE "ProductDate", "Tue, 28 May 2013 19:22:53 GMT\0"
+ VALUE "ProductDate", "Wed, 05 Jun 2013 09:42:53 GMT\0"
END
END