48 " |
48 " |
49 ! ! |
49 ! ! |
50 |
50 |
51 !PPCBenchmark methodsFor:'benchmark support'! |
51 !PPCBenchmark methodsFor:'benchmark support'! |
52 |
52 |
|
53 compile: value |
|
54 compile := value |
|
55 ! |
|
56 |
53 createContext |
57 createContext |
54 ^ contextClass new |
58 ^ contextClass new |
55 ! |
|
56 |
|
57 endSuite |
|
58 ! |
59 ! |
59 |
60 |
60 initialize |
61 initialize |
61 super initialize. |
62 super initialize. |
62 sources := PPCBenchmarkResources new. |
63 sources := PPCBenchmarkResources new. |
63 contextClass := PPCContext. |
64 contextClass := PPCContext. |
64 compile := false. |
65 compile := false. |
65 ! |
66 ! |
66 |
67 |
67 measure: parser on: input |
|
68 self measure: parser on: input name: #unknown |
|
69 ! |
|
70 |
|
71 measure: aParser on: anInput name: aString |
68 measure: aParser on: anInput name: aString |
72 | time result p | |
69 | time result p | |
73 context := self createContext. |
70 context := self createContext. |
74 |
71 |
75 compile ifTrue: [ |
72 p := compile ifTrue: [ |
76 p := (aParser end compile: #TmpBenchmark) |
73 aParser end compile |
77 ] ifFalse: [ |
74 ] ifFalse: [ |
78 p := aParser end. |
75 aParser end |
79 ]. |
76 ]. |
80 |
77 |
81 |
78 |
82 time := Time millisecondsToRun: [ result := p parse: anInput withContext: context ]. |
79 time := Time millisecondsToRun: [ result := p parse: anInput withContext: context ]. |
83 |
80 |
84 self assert: result isPetitFailure not. |
81 self assert: result isPetitFailure not. |
85 self reportFor: aParser context: context input: anInput time: time name: aString. |
82 self reportFor: aParser context: context input: anInput time: time name: aString. |
86 ! |
|
87 |
|
88 measure: parser onSources: inputs name: aString |
|
89 | time result context p totalInput | |
|
90 |
|
91 compile ifTrue: [ |
|
92 p := (parser end compile: #TmpBenchmark) |
|
93 ] ifFalse: [ |
|
94 p := parser end. |
|
95 ]. |
|
96 |
|
97 totalInput := ''. |
|
98 time := 0. |
|
99 inputs do: [:input | |
|
100 context := self createContext. |
|
101 time := time + (Time millisecondsToRun: [ result := p parse: input withContext: context ]). |
|
102 totalInput := totalInput, input. |
|
103 self assert: result isPetitFailure not. |
|
104 ]. |
|
105 |
|
106 |
|
107 self reportFor: parser context: context input: totalInput time: time name: aString. |
|
108 ! |
|
109 |
|
110 reportFor: parser context: context input: input time: time |
|
111 self reportFor: parser context: context input: input time: time name: #unknown |
|
112 ! |
83 ! |
113 |
84 |
114 reportFor: aParser context: aContext input: anInput time: time name: name |
85 reportFor: aParser context: aContext input: anInput time: time name: name |
115 Transcript crShow: (self getMetaInfo: name). |
86 Transcript crShow: (self getMetaInfo: name). |
116 Transcript crShow: ' Compile: ', compile asString. |
87 Transcript crShow: ' Compile: ', compile asString. |
129 ((aContext rememberCount / input size) asFloat asString truncateTo: 6), |
100 ((aContext rememberCount / input size) asFloat asString truncateTo: 6), |
130 '.'. |
101 '.'. |
131 " |
102 " |
132 ! |
103 ! |
133 |
104 |
134 startSuite |
105 reportInput: input time: time name: name |
135 Transcript crShow: Date current asString, ' ', Time current asString. |
106 | size | |
|
107 size := input inject: 0 into: [:r :e | r + e size ]. |
|
108 Transcript crShow: 'Size: ', size asString. |
|
109 Transcript crShow: name, ' time: ', time asString. |
|
110 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
136 ! ! |
111 ! ! |
137 |
112 |
138 !PPCBenchmark methodsFor:'benchmarks'! |
113 !PPCBenchmark methodsFor:'benchmarks'! |
139 |
|
140 benchmarkAnyStar |
|
141 " |
|
142 self measure: self anyStar on: sources petitParserPackage. |
|
143 " |
|
144 self measure: self anyStar on: (sources changesSized: 1000*1000) name: #anyStar. |
|
145 ! |
|
146 |
|
147 benchmarkAnyStarBlock |
|
148 " |
|
149 self measure: self anyStar on: sources petitParserPackage. |
|
150 " |
|
151 self measure: self anyStarBlock on: (sources changesSized: 1000*1000) name: #anyStarBlock. |
|
152 ! |
|
153 |
|
154 benchmarkAttributes |
|
155 | string text allStyles | |
|
156 string := (self changesSized: 60000). |
|
157 text := string asText. |
|
158 allStyles := { |
|
159 'Announcement' -> TextColor green. |
|
160 'Collections' -> TextColor blue. |
|
161 'File' -> TextColor blue. |
|
162 'Metacello' -> TextColor red. |
|
163 'Monticello' -> TextColor magenta. |
|
164 'Morphic' -> TextColor orange. |
|
165 'Mooose' -> TextColor green. |
|
166 'FAMIX' -> TextColor green. |
|
167 'Roassal' -> TextColor green. |
|
168 }. |
|
169 |
|
170 allStyles do: [ :assoc | | parser result time | |
|
171 parser := (assoc key asParser, #newline asParser negate star). |
|
172 time := Time millisecondsToRun: [ |
|
173 result := parser matchingRangesIn: string. |
|
174 ]. |
|
175 self reportFor: parser input: string time: time. |
|
176 ]. |
|
177 ! |
|
178 |
|
179 benchmarkBacktrack |
|
180 " |
|
181 self measure: self anyStar on: sources petitParserPackage. |
|
182 " |
|
183 | parser | |
|
184 parser := ((#any asParser, 'foo' asParser) / self tokenParser / #any asParser) plus. |
|
185 self measure: parser on: (self changesSized: 100*1000) name: #backtrack. |
|
186 ! |
|
187 |
|
188 benchmarkJava |
|
189 | parser | |
|
190 parser := PPJavaParser new. |
|
191 self measure: parser on: sources javaLangMath name: #java. |
|
192 ! |
|
193 |
114 |
194 benchmarkJavaSyntax |
115 benchmarkJavaSyntax |
195 | time | |
116 | time | |
196 |
117 |
197 self assert: '../java-src' asFileReference exists description: '../java-src directory with java sources expected'. |
118 self assert: '../java-src' asFileReference exists description: '../java-src directory with java sources expected'. |
296 input := sources smalltalkSourcesBig. |
202 input := sources smalltalkSourcesBig. |
297 |
203 |
298 time := [ input do: [ :source | parser parse: source withContext: context ]] timeToRun asMilliSeconds. |
204 time := [ input do: [ :source | parser parse: source withContext: context ]] timeToRun asMilliSeconds. |
299 |
205 |
300 self reportInput: input time: time name: 'Smalltalk Parser Compiled'. |
206 self reportInput: input time: time name: 'Smalltalk Parser Compiled'. |
|
207 ! ! |
|
208 |
|
209 !PPCBenchmark methodsFor:'benchmarks - micro'! |
|
210 |
|
211 benchmarkAnyStar |
|
212 " |
|
213 self measure: self anyStar on: sources petitParserPackage. |
|
214 " |
|
215 self measure: self anyStar on: (sources changesSized: 1000*1000) name: #anyStar. |
|
216 ! |
|
217 |
|
218 benchmarkAnyStarBlock |
|
219 " |
|
220 self measure: self anyStar on: sources petitParserPackage. |
|
221 " |
|
222 self measure: self anyStarBlock on: (sources changesSized: 1000*1000) name: #anyStarBlock. |
301 ! |
223 ! |
302 |
224 |
303 benchmarkToken |
225 benchmarkToken |
304 " |
226 " |
305 self measure: self anyStar on: sources petitParserPackage. |
227 self measure: self anyStar on: sources petitParserPackage. |
306 " |
228 " |
307 | parser | |
|
308 parser := (self tokenParser / #any asParser) star. |
229 parser := (self tokenParser / #any asParser) star. |
309 self measure: parser on: (self changesSized: 1000*1000) name: #token. |
230 self measure: parser on: (sources changesSized: 1000*1000) name: #token. |
310 ! |
|
311 |
|
312 reportInput: input time: time name: name |
|
313 | size | |
|
314 size := input inject: 0 into: [:r :e | r + e size ]. |
|
315 Transcript crShow: 'Size: ', size asString. |
|
316 Transcript crShow: name, ' time: ', time asString. |
|
317 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
318 ! ! |
231 ! ! |
319 |
232 |
320 !PPCBenchmark methodsFor:'benchmarks-CalipeL'! |
233 !PPCBenchmark methodsFor:'benchmarks-CalipeL'! |
321 |
234 |
322 benchmarkJavaSyntaxC |
235 benchmarkJavaSyntaxC |
370 <teardown: #teardownSmalltalkParserCompiledC> |
283 <teardown: #teardownSmalltalkParserCompiledC> |
371 <benchmark: 'Petit Smalltalk Parser - Compiled'> |
284 <benchmark: 'Petit Smalltalk Parser - Compiled'> |
372 |
285 |
373 input do: [ :source | parser parse: source withContext: context ] |
286 input do: [ :source | parser parse: source withContext: context ] |
374 |
287 |
|
288 ! ! |
|
289 |
|
290 !PPCBenchmark methodsFor:'benchmarks-CalipeL- setup & teardown'! |
|
291 |
|
292 setupJavaSyntaxC |
|
293 |
|
294 parser := PPJavaSyntax new. |
|
295 context := PPCContext new. |
|
296 context initializeFor: parser. |
|
297 input := sources javaSourcesBig. |
|
298 ! |
|
299 |
|
300 setupJavaSyntaxCompiledC |
|
301 parser := PPJavaSyntax new compile. |
|
302 context := PPCContext new. |
|
303 context initializeFor: parser. |
|
304 input := sources javaSourcesBig. |
|
305 |
|
306 " |
|
307 size := input inject: 0 into: [:r :e | r + e size ]. |
|
308 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
309 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
310 " |
|
311 ! |
|
312 |
|
313 setupRBParserC |
|
314 |
|
315 input := sources smalltalkSourcesBig. |
|
316 ! |
|
317 |
|
318 setupSmalltalkGrammarC |
|
319 |
|
320 parser := PPSmalltalkGrammar new. |
|
321 context := PPCContext new. |
|
322 context initializeFor: parser. |
|
323 input := sources smalltalkSourcesBig. |
|
324 ! |
|
325 |
|
326 setupSmalltalkGrammarCompiledC |
|
327 parser := PPSmalltalkGrammar new compile. |
|
328 context := PPCContext new. |
|
329 context initializeFor: parser. |
|
330 input := sources smalltalkSourcesBig. |
|
331 |
|
332 " |
|
333 size := input inject: 0 into: [:r :e | r + e size ]. |
|
334 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
335 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
336 " |
|
337 ! |
|
338 |
|
339 setupSmalltalkParserC |
|
340 |
|
341 parser := PPSmalltalkParser new. |
|
342 context := PPCContext new. |
|
343 context initializeFor: parser. |
|
344 input := sources smalltalkSourcesBig. |
|
345 ! |
|
346 |
|
347 setupSmalltalkParserCompiledC |
|
348 parser := PPSmalltalkParser new compile. |
|
349 context := PPCContext new. |
|
350 context initializeFor: parser. |
|
351 input := sources smalltalkSourcesBig. |
|
352 |
|
353 " |
|
354 size := input inject: 0 into: [:r :e | r + e size ]. |
|
355 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
356 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
357 " |
|
358 ! |
|
359 |
|
360 teardownJavaSyntaxCompiledC |
|
361 parser class removeFromSystem. |
|
362 " |
|
363 size := input inject: 0 into: [:r :e | r + e size ]. |
|
364 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
365 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
366 " |
|
367 ! |
|
368 |
|
369 teardownSmalltalkGrammarCompiledC |
|
370 parser class removeFromSystem. |
|
371 " |
|
372 size := input inject: 0 into: [:r :e | r + e size ]. |
|
373 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
374 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
375 " |
|
376 ! |
|
377 |
|
378 teardownSmalltalkParserCompiledC |
|
379 parser class removeFromSystem. |
|
380 " |
|
381 size := input inject: 0 into: [:r :e | r + e size ]. |
|
382 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
383 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
384 " |
375 ! ! |
385 ! ! |
376 |
386 |
377 !PPCBenchmark methodsFor:'meta'! |
387 !PPCBenchmark methodsFor:'meta'! |
378 |
388 |
379 getMetaInfo: key |
389 getMetaInfo: key |
403 |
414 |
404 tokenParser |
415 tokenParser |
405 ^ #letter asParser, (#letter asParser / #digit asParser) star trim |
416 ^ #letter asParser, (#letter asParser / #digit asParser) star trim |
406 ! ! |
417 ! ! |
407 |
418 |
408 !PPCBenchmark methodsFor:'settings'! |
|
409 |
|
410 compile: aBoolean |
|
411 compile := aBoolean |
|
412 ! |
|
413 |
|
414 contextClass: aClass |
|
415 contextClass := aClass |
|
416 ! ! |
|
417 |
|
418 !PPCBenchmark methodsFor:'setup & teardown-CalipeL'! |
|
419 |
|
420 setupJavaSyntaxC |
|
421 |
|
422 ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[ |
|
423 BenchmarkSkipRequest signal. |
|
424 ]. |
|
425 |
|
426 parser := PPJavaSyntax new. |
|
427 context := PPCContext new. |
|
428 context initializeFor: parser. |
|
429 input := sources javaSourcesBig. |
|
430 |
|
431 "Modified: / 20-04-2015 / 12:55:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
432 ! |
|
433 |
|
434 setupJavaSyntaxCompiledC |
|
435 ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[ |
|
436 BenchmarkSkipRequest signal. |
|
437 ]. |
|
438 parser := PPJavaSyntax new compile. |
|
439 context := PPCContext new. |
|
440 context initializeFor: parser. |
|
441 input := sources javaSourcesBig. |
|
442 |
|
443 " |
|
444 size := input inject: 0 into: [:r :e | r + e size ]. |
|
445 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
446 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
447 " |
|
448 |
|
449 "Modified: / 20-04-2015 / 12:55:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
450 ! |
|
451 |
|
452 setupRBParserC |
|
453 |
|
454 input := sources smalltalkSourcesBig. |
|
455 ! |
|
456 |
|
457 setupSmalltalkGrammarC |
|
458 |
|
459 parser := PPSmalltalkGrammar new. |
|
460 context := PPCContext new. |
|
461 context initializeFor: parser. |
|
462 input := sources smalltalkSourcesBig. |
|
463 ! |
|
464 |
|
465 setupSmalltalkGrammarCompiledC |
|
466 parser := PPSmalltalkGrammar new compile. |
|
467 context := PPCContext new. |
|
468 context initializeFor: parser. |
|
469 input := sources smalltalkSourcesBig. |
|
470 |
|
471 " |
|
472 size := input inject: 0 into: [:r :e | r + e size ]. |
|
473 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
474 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
475 " |
|
476 ! |
|
477 |
|
478 setupSmalltalkParserC |
|
479 |
|
480 parser := PPSmalltalkParser new. |
|
481 context := PPCContext new. |
|
482 context initializeFor: parser. |
|
483 input := sources smalltalkSourcesBig. |
|
484 ! |
|
485 |
|
486 setupSmalltalkParserCompiledC |
|
487 parser := PPSmalltalkParser new compile. |
|
488 context := PPCContext new. |
|
489 context initializeFor: parser. |
|
490 input := sources smalltalkSourcesBig. |
|
491 |
|
492 " |
|
493 size := input inject: 0 into: [:r :e | r + e size ]. |
|
494 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
495 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
496 " |
|
497 ! |
|
498 |
|
499 teardownJavaSyntaxCompiledC |
|
500 parser notNil ifTrue:[ |
|
501 parser class removeFromSystem. |
|
502 ]. |
|
503 " |
|
504 size := input inject: 0 into: [:r :e | r + e size ]. |
|
505 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
506 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
507 " |
|
508 ! |
|
509 |
|
510 teardownSmalltalkGrammarCompiledC |
|
511 parser notNil ifTrue:[ |
|
512 parser class removeFromSystem. |
|
513 ]. |
|
514 " |
|
515 size := input inject: 0 into: [:r :e | r + e size ]. |
|
516 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
517 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
518 " |
|
519 ! |
|
520 |
|
521 teardownSmalltalkParserCompiledC |
|
522 parser class removeFromSystem. |
|
523 " |
|
524 size := input inject: 0 into: [:r :e | r + e size ]. |
|
525 Transcript crShow: 'Compiled Grammar time: ', time asString. |
|
526 Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'. |
|
527 " |
|
528 ! ! |
|
529 |
|
530 !PPCBenchmark methodsFor:'sources'! |
|
531 |
|
532 changesSized: size |
|
533 | string changes | |
|
534 changes := PharoFilesOpener default changesFileOrNil contents. |
|
535 string := changes copyFrom: 1 to: size. |
|
536 ^ string |
|
537 |
|
538 ! ! |
|
539 |
|
540 !PPCBenchmark methodsFor:'suites'! |
|
541 |
|
542 suite1 |
|
543 self startSuite. |
|
544 |
|
545 self benchmarkNegate. |
|
546 self benchmarkBacktrack. |
|
547 self benchmarkToken. |
|
548 self benchmarkAnyStar. |
|
549 self benchmarkJava. |
|
550 |
|
551 self endSuite. |
|
552 ! ! |
|
553 |
|
554 !PPCBenchmark class methodsFor:'documentation'! |
419 !PPCBenchmark class methodsFor:'documentation'! |
555 |
420 |
556 version_HG |
421 version_HG |
557 |
422 |
558 ^ '$Changeset: <not expanded> $' |
423 ^ '$Changeset: <not expanded> $' |