1762
|
1 |
"{ Package: 'stx:libjava/benchmarks' }"
|
|
2 |
|
|
3 |
StandaloneStartup subclass:#JavaBenchmarkRunner
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Benchmarks-Java-Framework'
|
|
8 |
!
|
|
9 |
|
1788
|
10 |
JavaBenchmarkRunner class instanceVariableNames:'benchmark passes variant debugging profiler'
|
1762
|
11 |
|
|
12 |
"
|
|
13 |
The following class instance variables are inherited by this class:
|
|
14 |
|
|
15 |
StandaloneStartup - MutexHandle
|
|
16 |
Object -
|
|
17 |
"
|
|
18 |
!
|
|
19 |
|
|
20 |
|
|
21 |
!JavaBenchmarkRunner class methodsFor:'initialization'!
|
|
22 |
|
|
23 |
initialize
|
|
24 |
|
|
25 |
super initialize.
|
|
26 |
debugging := Transcript notNil and:[Transcript isView].
|
1780
|
27 |
variant := #runJ:
|
1762
|
28 |
|
|
29 |
"Created: / 06-11-2011 / 22:07:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1780
|
30 |
"Modified: / 31-10-2012 / 23:42:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
31 |
! !
|
|
32 |
|
1788
|
33 |
!JavaBenchmarkRunner class methodsFor:'accessing'!
|
|
34 |
|
|
35 |
profiler
|
|
36 |
^ profiler
|
|
37 |
! !
|
|
38 |
|
1762
|
39 |
!JavaBenchmarkRunner class methodsFor:'command line options'!
|
|
40 |
|
|
41 |
cmdlineOptionBenchmark
|
|
42 |
|
|
43 |
^CmdLineOption new
|
|
44 |
short: $b;
|
1769
|
45 |
long: 'benchmark';
|
1762
|
46 |
description: 'benchmark to run (class name)';
|
|
47 |
action:[:option |
|
|
48 |
benchmark := Smalltalk at: option asSymbol.
|
|
49 |
benchmark isNil ifTrue:[
|
|
50 |
Stderr nextPutLine: 'ERROR: No such benchmark: ', option.
|
1788
|
51 |
self exit: 0.
|
1762
|
52 |
]
|
|
53 |
]
|
|
54 |
|
|
55 |
"Created: / 31-10-2012 / 10:49:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1788
|
56 |
"Modified: / 02-11-2012 / 02:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
57 |
!
|
|
58 |
|
|
59 |
cmdlineOptionJava
|
|
60 |
|
|
61 |
^CmdLineOption new
|
|
62 |
short: $j;
|
1769
|
63 |
long: 'java';
|
1762
|
64 |
description: 'run Java version of the benchmark (default)';
|
|
65 |
action:[
|
1780
|
66 |
variant := #runJ:
|
1762
|
67 |
]
|
|
68 |
|
|
69 |
"Created: / 31-10-2012 / 11:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1780
|
70 |
"Modified: / 31-10-2012 / 23:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
71 |
!
|
|
72 |
|
|
73 |
cmdlineOptionPasses
|
|
74 |
|
|
75 |
^CmdLineOption new
|
|
76 |
short: $n;
|
1769
|
77 |
long: 'passed';
|
1762
|
78 |
description: 'how many passes to run (integer)';
|
|
79 |
action:[:option |
|
|
80 |
passes := Integer readFrom: option onError:[
|
|
81 |
Stderr nextPutLine: 'ERROR: Not an integer value: ', option.
|
1788
|
82 |
self exit: 0.
|
1762
|
83 |
]
|
|
84 |
]
|
|
85 |
|
|
86 |
"Created: / 31-10-2012 / 10:52:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1788
|
87 |
"Modified: / 02-11-2012 / 02:32:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
88 |
!
|
|
89 |
|
|
90 |
cmdlineOptionSmalltak
|
|
91 |
|
|
92 |
^CmdLineOption new
|
|
93 |
short: $s;
|
1769
|
94 |
long: 'smalltalk';
|
1762
|
95 |
description: 'run Smalltalk version of the benchmark';
|
|
96 |
action:[
|
1780
|
97 |
variant := #runS:
|
1762
|
98 |
]
|
|
99 |
|
|
100 |
"Created: / 31-10-2012 / 11:04:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1780
|
101 |
"Modified: / 31-10-2012 / 23:41:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
102 |
!
|
|
103 |
|
|
104 |
cmdlineOptionSmalltak2Java
|
|
105 |
|
|
106 |
^CmdLineOption new
|
|
107 |
short: $k;
|
|
108 |
long: 'smalltalk2java';
|
|
109 |
description: 'run cross-language version of the benchmark';
|
|
110 |
action:[
|
|
111 |
variant := #runS2J:
|
|
112 |
]
|
|
113 |
|
|
114 |
"Created: / 31-10-2012 / 23:42:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
115 |
! !
|
|
116 |
|
|
117 |
!JavaBenchmarkRunner class methodsFor:'defaults'!
|
|
118 |
|
|
119 |
allowCoverageMeasurementOption
|
|
120 |
|
|
121 |
^true
|
|
122 |
|
|
123 |
"Created: / 13-01-2012 / 11:48:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
124 |
"Modified: / 31-10-2012 / 10:38:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
125 |
!
|
|
126 |
|
|
127 |
allowDebugOption
|
|
128 |
|
|
129 |
^true
|
|
130 |
|
|
131 |
"Created: / 21-07-2011 / 09:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
132 |
! !
|
|
133 |
|
|
134 |
!JavaBenchmarkRunner class methodsFor:'startup'!
|
|
135 |
|
|
136 |
setupToolsForDebug
|
|
137 |
|
|
138 |
super setupToolsForDebug.
|
|
139 |
debugging := true.
|
|
140 |
|
|
141 |
"Created: / 06-11-2011 / 22:06:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
142 |
!
|
|
143 |
|
|
144 |
usage
|
|
145 |
|
|
146 |
Stderr nextPutLine:'usage:'; cr;
|
|
147 |
nextPutAll:' benchmark-runner.';
|
|
148 |
nextPutAll: (OperatingSystem isMSWINDOWSlike ifTrue:['bat'] ifFalse:['sh']);
|
|
149 |
nextPutAll: ' -b <benchmark> -n <n>'; cr; cr.
|
|
150 |
|
|
151 |
Stderr nextPutLine:' --help .................. output this message'.
|
|
152 |
"/ Stderr nextPutLine:' --verbose ............... verbose startup'.
|
|
153 |
"/ Stderr nextPutLine:' --noBanner .............. no splash screen'.
|
|
154 |
"/ Stderr nextPutLine:' --newAppInstance ........ start as its own application process (do not reuse a running instance)'.
|
|
155 |
"/ self allowScriptingOption ifTrue:[
|
|
156 |
"/ Stderr nextPutLine:' --scripting portNr ...... enable scripting via port (or stdin/stdOut, if 0)'.
|
|
157 |
"/ ].
|
|
158 |
self allowDebugOption ifTrue:[
|
|
159 |
Stderr nextPutLine:' --debug ................. enable Debugger'.
|
|
160 |
].
|
|
161 |
|
|
162 |
"/ ' ......................... '
|
|
163 |
Stderr nextPutLine:' -b <benchmark>'.
|
|
164 |
Stderr nextPutLine:' --benchmark=<benchmark> . benchmark to run (class name)'.
|
|
165 |
Stderr nextPutLine:' -n <n>'.
|
|
166 |
Stderr nextPutLine:' --passes ................ how many passes of given benchmark (integer)'.
|
|
167 |
Stderr nextPutLine:' -j'.
|
|
168 |
Stderr nextPutLine:' --java ..,............... run Java version of the benchmark (default)'.
|
|
169 |
Stderr nextPutLine:' -s'.
|
|
170 |
Stderr nextPutLine:' --smalltalk ............. run Smalltalk version of the benchmark'.
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
"
|
|
175 |
self usage
|
|
176 |
"
|
|
177 |
|
|
178 |
"Created: / 13-01-2012 / 11:48:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
179 |
"Modified: / 31-10-2012 / 11:05:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
180 |
! !
|
|
181 |
|
|
182 |
!JavaBenchmarkRunner class methodsFor:'startup-to be redefined'!
|
|
183 |
|
1788
|
184 |
exit: code
|
|
185 |
debugging ifFalse:[
|
|
186 |
Smalltalk exit: code
|
|
187 |
].
|
|
188 |
|
|
189 |
"Created: / 02-11-2012 / 02:32:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
190 |
!
|
|
191 |
|
1780
|
192 |
main:argv
|
1762
|
193 |
|
|
194 |
"Process command line arguments"
|
|
195 |
| parser |
|
|
196 |
|
|
197 |
parser := CmdLineParser new.
|
|
198 |
[
|
|
199 |
parser parse: argv for: self.
|
|
200 |
] on: Error do:[:ex|
|
|
201 |
Stderr nextPutLine:'Error when processing options: ', ex description.
|
|
202 |
debugging ifFalse:[
|
|
203 |
ex suspendedContext fullPrintAllOn: Stderr.
|
|
204 |
Stderr nextPutLine:'Exiting'.
|
|
205 |
Smalltalk exit:1.
|
|
206 |
] ifTrue:[
|
|
207 |
ex pass
|
|
208 |
]
|
|
209 |
].
|
|
210 |
|
1798
|
211 |
"Set stack size to 16MB"
|
|
212 |
Processor activeProcess setMaximumStackSize: ((1024 * 1024 * 16) max: Process defaultMaximumStackSize).
|
|
213 |
|
|
214 |
"Setup for performance"
|
|
215 |
JavaNativeMethod cacheNativeImplementation: true.
|
|
216 |
ObjectMemory justInTimeCompilation: true.
|
|
217 |
ObjectMemory javaNativeCodeOptimization:true.
|
|
218 |
ObjectMemory javaJustInTimeCompilation: true.
|
|
219 |
|
1762
|
220 |
[
|
|
221 |
| time |
|
|
222 |
|
1789
|
223 |
Profiler valgrind runningUnderValgrind ifTrue:[
|
|
224 |
profiler := #callgrind
|
|
225 |
].
|
|
226 |
|
1788
|
227 |
time := benchmark new
|
|
228 |
profiler: profiler;
|
|
229 |
perform: variant with: passes.
|
1766
|
230 |
Stdout nextPutLine: 'EXECUTION TIME: ' , time printString.
|
1762
|
231 |
|
|
232 |
debugging ifFalse:[
|
|
233 |
Smalltalk exit:0.
|
|
234 |
].
|
|
235 |
] on: Error do:[:ex|
|
|
236 |
Stderr nextPutAll:'Error when running benchmark: '.
|
|
237 |
Stderr nextPutAll:ex description; cr.
|
|
238 |
ex suspendedContext printAllOn:Stderr.
|
|
239 |
debugging ifFalse:[
|
|
240 |
Smalltalk exit:1.
|
|
241 |
] ifTrue:[
|
|
242 |
ex pass
|
|
243 |
]
|
|
244 |
]
|
|
245 |
|
1788
|
246 |
"Modified: / 02-11-2012 / 02:26:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1762
|
247 |
! !
|
|
248 |
|
|
249 |
!JavaBenchmarkRunner class methodsFor:'documentation'!
|
|
250 |
|
|
251 |
version_SVN
|
|
252 |
^ '$Id:: $'
|
|
253 |
! !
|
|
254 |
|
|
255 |
JavaBenchmarkRunner initialize!
|