-
Notifications
You must be signed in to change notification settings - Fork 65
/
SMarkHarnessArgumentParser.class.st
152 lines (127 loc) · 3.87 KB
/
SMarkHarnessArgumentParser.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Class {
#name : #SMarkHarnessArgumentParser,
#superclass : #Object,
#instVars : [
'runner',
'reporter',
'suiteOrBenchmark',
'iterations',
'processes',
'problemSize',
'i',
'current',
'numParams',
'currentObj',
'arguments',
'suite',
'specificBenchmark',
'suiteClass',
'harness'
],
#category : #'CogBenchmarks-SMark'
}
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> determineBenchmarkParameters [
"Initialize with defaults, will be overwritten in case
it is specified."
iterations := runner class defaultNumberOfIterations.
processes := runner class defaultNumberOfProcesses.
problemSize:= suiteClass defaultProblemSize.
self determineBenchmarkParametersFromArguments.
]
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> determineBenchmarkParametersFromArguments [
i := i + 1.
i <= numParams ifTrue: [
iterations := (arguments at: i) asInteger.
i := i + 1.
i <= numParams ifTrue: [
processes := (arguments at: i) asInteger.
i := i + 1.
i <= numParams ifTrue: [
problemSize := arguments at: i.
]
]
].
]
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> determineReporter [
(currentObj isKindOf: SMarkReporter)
ifFalse: [ reporter := harness defaultReporter new. ]
ifTrue: [ reporter := currentObj.
i := i + 1.
i <= numParams ifTrue: [
current := arguments at: i.
]
].
]
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> determineRunner [
(currentObj isKindOf: SMarkRunner)
ifFalse: [ runner := harness defaultRunner new. ]
ifTrue: [ runner := currentObj.
i := i + 1.
i <= numParams ifTrue: [
current := arguments at: i.
currentObj := (Smalltalk classNamed: current) ifNotNilDo: [:cls | cls new].
]
].
]
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> determineSuiteOrBenchmark [
self parseBenchmarkOrSuite: current.
]
{ #category : #accessing }
SMarkHarnessArgumentParser >> harness: aHarness [
harness := aHarness
]
{ #category : #helper }
SMarkHarnessArgumentParser >> instructRunner [
suite := suiteClass new.
specificBenchmark ifNotNil: [
suite runOnly: specificBenchmark.
].
runner suite: suite.
runner iterations: iterations.
runner processes: processes.
runner problemSize: problemSize.
]
{ #category : #parsing }
SMarkHarnessArgumentParser >> parse: argumentsArray [
arguments := argumentsArray.
numParams := arguments size.
i := 2.
current := arguments at: i.
currentObj := (Smalltalk classNamed: current) ifNotNilDo: [:cls | cls new].
self determineRunner.
self determineReporter.
self determineSuiteOrBenchmark.
self determineBenchmarkParameters.
self instructRunner.
^ {runner. reporter}
]
{ #category : #'argument parsing' }
SMarkHarnessArgumentParser >> parseBenchmarkOrSuite: aBenchmarkOrSuite [
"Identify the benchmark suite or suite and benchmark method
that should be executed. The string should be of the format 'Class>>benchName' or 'Class.benchName' for shell/bash compatibility.
Accepts a string, class, or array.
Returns, a class, or an array of a class and a symbol."
| parsed |
(aBenchmarkOrSuite isKindOf: Class)
ifTrue: [
suiteClass := aBenchmarkOrSuite.
^ suiteClass
].
(aBenchmarkOrSuite isKindOf: Array)
ifTrue: [ parsed := aBenchmarkOrSuite. ]
ifFalse: [ parsed := aBenchmarkOrSuite findTokens: '>.'. ].
((parsed size > 2) or: [parsed size < 1])
ifTrue: [ Error signal: 'The passed argument has to represent two elements. A class/classname and a method symbol' ].
suiteClass := parsed first.
(suiteClass isKindOf: Class)
ifFalse: [ suiteClass := Smalltalk at: (suiteClass asSymbol) ifAbsent: [Error signal: 'Class that was supposed to represent a benchmark suite was not found: ', suiteClass asString ]].
parsed size = 1
ifTrue: [^suiteClass].
specificBenchmark := parsed second asSymbol.
^ { suiteClass. specificBenchmark }
]