-
Notifications
You must be signed in to change notification settings - Fork 65
/
SMarkAutosizeRunner.class.st
86 lines (69 loc) · 2.69 KB
/
SMarkAutosizeRunner.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Class {
#name : #SMarkAutosizeRunner,
#superclass : #SMarkRunner,
#instVars : [
'targetTime',
'innerLoopIterations'
],
#category : #'CogBenchmarks-SMark'
}
{ #category : #defaults }
SMarkAutosizeRunner class >> defaultTargetTime [
"300 milliseconds seems to be a reasonable target time for most problems.
It is a compromise between the general measurment noise as well as timer accuracy
and the absolute runtime of benchmarks"
^ 300
]
{ #category : #initialization }
SMarkAutosizeRunner >> initialize [
super initialize.
targetTime := self class defaultTargetTime.
]
{ #category : #benchmarking }
SMarkAutosizeRunner >> performBenchmark: aSelector [
"First determine a useful number of inner loop iterations until the targetTime is reached."
| execTime i |
"make sure no timers are recorded for this"
timers := nil.
i := 1.
execTime := Time millisecondsToRun: [ suite perform: aSelector. ].
[ execTime > targetTime ] whileFalse: [
i := i * 2. "Was thinking of doing something fancy here, but just go with this simple staight-forward solution"
execTime := Time millisecondsToRun: [ 1 to: i do: [:ignored| suite perform: aSelector]].
].
innerLoopIterations := i.
"Then start executing the benchmark"
^ super performBenchmark: aSelector.
]
{ #category : #benchmarking }
SMarkAutosizeRunner >> runBaseBenchmark [
"baseBenchmark is not supported with autosizing. I do not see how that can be made possible since all different benchmarks will have different number of iterations, and the only way how a consistent baseline could be found would be to normalize the results, but well, incooprorating the baseline measurement with the statistical evaluation is harder than just substracting a one time value..., I am not going to do that here for the moment. Stefan 2011-03-20"
(suite respondsTo: #baseBenchmark)
ifFalse: [ ^ nil ].
"I decided to go here with a silent solution to avoid thinking about logging frameworks and Transcript to console convertion..."
self recordResults: (self class defaultTimer new: 'total') for: #baseBenchmark
]
{ #category : #accessing }
SMarkAutosizeRunner >> targetTime [
"Target time in milliseconds"
^ targetTime
]
{ #category : #accessing }
SMarkAutosizeRunner >> targetTime: anIntInMilliseconds [
"Target time in milliseconds"
targetTime := anIntInMilliseconds
]
{ #category : #benchmarking }
SMarkAutosizeRunner >> timedBenchmarkExecution: aSelector [
"Will do a timed execution of the benchmark and return the result timer"
| timer |
timers := Dictionary new.
timer := self createTimer: 'total'.
timer start.
1 to: innerLoopIterations do: [:ignored|
suite perform: aSelector.
].
timer stop.
self recordResults: timer for: aSelector.
^ timer
]