compiler/benchmarks/PPCBenchmark.st
changeset 515 b5316ef15274
parent 502 1e45d3c96ec5
child 516 3b81c9e53352
child 524 f6f68d32de73
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 Object subclass:#PPCBenchmark
     5 Object subclass:#PPCBenchmark
     6 	instanceVariableNames:'sources report contextClass compile parser context input
     6 	instanceVariableNames:'sources report contextClass compile parser context input
     7 		configuration profile'
     7 		configuration profile repetitions'
     8 	classVariableNames:''
     8 	classVariableNames:''
     9 	poolDictionaries:''
     9 	poolDictionaries:''
    10 	category:'PetitCompiler-Benchmarks-Core'
    10 	category:'PetitCompiler-Benchmarks-Core'
    11 !
    11 !
    12 
    12 
    61 
    61 
    62     "Created: / 11-05-2015 / 16:31:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    62     "Created: / 11-05-2015 / 16:31:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    63     "Modified: / 16-05-2015 / 19:19:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    63     "Modified: / 16-05-2015 / 19:19:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    64 ! !
    64 ! !
    65 
    65 
       
    66 !PPCBenchmark methodsFor:'accessing'!
       
    67 
       
    68 repetitions
       
    69     ^ repetitions
       
    70 !
       
    71 
       
    72 repetitions: anObject
       
    73     repetitions := anObject
       
    74 ! !
       
    75 
    66 !PPCBenchmark methodsFor:'benchmark support'!
    76 !PPCBenchmark methodsFor:'benchmark support'!
    67 
    77 
    68 compile: value
    78 compile: value
    69     compile := value
    79     compile := value
    70 !
    80 !
   261 benchmarkSmalltalkGrammarCompiled
   271 benchmarkSmalltalkGrammarCompiled
   262     | time  |
   272     | time  |
   263 
   273 
   264     self setupSmalltalkGrammarCompiled.
   274     self setupSmalltalkGrammarCompiled.
   265 
   275 
   266     time := [ input do: [ :source | parser parse: source withContext: context ]] timeToRun asMilliSeconds.
   276     repetitions timesRepeat: [ 
   267     
   277         time := [ input do: [ :source | 
   268     self reportInput: input time: time name: 'Compiled Smalltalk Grammar'.
   278             parser parse: source withContext: context 
   269 
   279         ]] timeToRun asMilliSeconds.
   270 "	
   280         self reportInput: input time: time name: 'Compiled Smalltalk Grammar'.
   271     size := input inject: 0 into: [:r :e | r + e size  ].
   281     ]
   272     Transcript crShow: 'Compiled Grammar time: ', time asString.
       
   273     Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'.
       
   274 "
       
   275 !
   282 !
   276 
   283 
   277 benchmarkSmalltalkGrammarTokenized
   284 benchmarkSmalltalkGrammarTokenized
   278     | time   |
   285     | time   |
   279 
   286 
   280     self setupSmalltalkGrammarTokenized.
   287     self setupSmalltalkGrammarTokenized.
   281     
   288     
   282     time := [ input do: [ :source | 
   289     repetitions timesRepeat: [ 	
   283             parser parse: source withContext: context ] 
   290         time := [ input do: [ :source | 
   284     ] timeToRun asMilliSeconds.
   291                 parser parse: source withContext: context ] 
   285     
   292         ] timeToRun asMilliSeconds.
   286     self reportInput: input time: time name: 'Tokenized Smalltalk Grammar'.
   293         self reportInput: input time: time name: 'Tokenized Smalltalk Grammar'.
   287 
   294     ]
   288 "	
   295 "	
   289     size := input inject: 0 into: [:r :e | r + e size  ].
   296     size := input inject: 0 into: [:r :e | r + e size  ].
   290     Transcript crShow: 'Compiled Grammar time: ', time asString.
   297     Transcript crShow: 'Compiled Grammar time: ', time asString.
   291     Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'.
   298     Transcript crShow: 'Time per character: ', (time / size * 1000.0) asString, ' microseconds'.
   292 "
   299 "
   441     sources := PPCResources current.
   448     sources := PPCResources current.
   442     contextClass := PPCContext.
   449     contextClass := PPCContext.
   443 
   450 
   444     compile := false.
   451     compile := false.
   445     profile := false.
   452     profile := false.
       
   453     
       
   454     repetitions := 3
   446 ! !
   455 ! !
   447 
   456 
   448 !PPCBenchmark methodsFor:'meta'!
   457 !PPCBenchmark methodsFor:'meta'!
   449 
   458 
   450 getMetaInfo: key
   459 getMetaInfo: key
   495 !
   504 !
   496 
   505 
   497 setupExpressionGrammarCompiled
   506 setupExpressionGrammarCompiled
   498     
   507     
   499     configuration := PPCConfiguration universal.
   508     configuration := PPCConfiguration universal.
   500     configuration arguments name: #PPCompiledExpressionGrammar.
   509     configuration arguments parserName: #PPCompiledExpressionGrammar.
       
   510     configuration arguments scannerName: #PPCompiledExpressionScanner.
   501     parser := PPExpressionGrammar new compileWithConfiguration: configuration.
   511     parser := PPExpressionGrammar new compileWithConfiguration: configuration.
   502     context := self context.
   512     context := self context.
   503     context initializeFor: parser.
   513     context initializeFor: parser.
   504     input := sources expressionSourcesMedium.
   514     input := sources expressionSourcesMedium.
   505 !
   515 !
   506 
   516 
   507 setupExpressionGrammarTokenized
   517 setupExpressionGrammarTokenized
   508     
   518     
   509     configuration := PPCConfiguration tokenizing.
   519     configuration := PPCConfiguration tokenizing.
   510     configuration arguments name: #PPTokenizedExpressionGrammar.
   520     configuration arguments parserName: #PPTokenizedExpressionGrammar.
       
   521     configuration arguments scannerName: #PPTokenizedExpressionScanner.
   511     parser := PPExpressionGrammar new compileWithConfiguration: configuration.
   522     parser := PPExpressionGrammar new compileWithConfiguration: configuration.
   512     context := self context.
   523     context := self context.
   513     context initializeFor: parser.
   524     context initializeFor: parser.
   514     input := sources expressionSourcesMedium.
   525     input := sources expressionSourcesMedium.
   515 !
   526 !
   544 !
   555 !
   545 
   556 
   546 setupLL1ExpressionGrammarCompiled
   557 setupLL1ExpressionGrammarCompiled
   547     
   558     
   548     configuration := PPCConfiguration universal.
   559     configuration := PPCConfiguration universal.
   549     configuration arguments name: #PPCompiledLL1ExpressionGrammar.
   560     configuration arguments parserName: #PPCompiledLL1ExpressionGrammar.
       
   561     configuration arguments scannerName: #PPCompiledLL1ExpressionScanner.
   550     parser := PPLL1ExpressionGrammar new compileWithConfiguration: configuration.
   562     parser := PPLL1ExpressionGrammar new compileWithConfiguration: configuration.
   551     context := self context.
   563     context := self context.
   552     context initializeFor: parser.
   564     context initializeFor: parser.
   553     input := sources expressionSourcesBig.
   565     input := sources expressionSourcesBig.
   554 !
   566 !
   555 
   567 
   556 setupLL1ExpressionGrammarTokenized
   568 setupLL1ExpressionGrammarTokenized
   557     
   569     
   558     configuration := PPCConfiguration tokenizing.
   570     configuration := PPCConfiguration tokenizing.
   559     configuration arguments name: #PPTokenizedLL1ExpressionGrammar.
   571     configuration arguments parserName: #PPTokenizedLL1ExpressionGrammar.
       
   572     configuration arguments scannerName: #PPTokenizedLL1ExpressionScanner.
   560     parser := PPLL1ExpressionGrammar new compileWithConfiguration: configuration.
   573     parser := PPLL1ExpressionGrammar new compileWithConfiguration: configuration.
   561     context := self context.
   574     context := self context.
   562     context initializeFor: parser.
   575     context initializeFor: parser.
   563     input := sources expressionSourcesBig.
   576     input := sources expressionSourcesBig.
   564 !
   577 !
   577 !
   590 !
   578 
   591 
   579 setupSmalltalkGrammarCompiled
   592 setupSmalltalkGrammarCompiled
   580 
   593 
   581     configuration := PPCConfiguration universal.
   594     configuration := PPCConfiguration universal.
   582     configuration arguments name: #PPCompiledSmalltalkGrammar.
   595     configuration arguments parserName: #PPCompiledSmalltalkGrammar.
       
   596     configuration arguments scannerName: #PPCompiledSmalltalkScanner.
   583     configuration arguments profile: profile.
   597     configuration arguments profile: profile.
   584     
   598     
   585     parser := PPSmalltalkGrammar new compileWithConfiguration: configuration.
   599     parser := PPSmalltalkGrammar new compileWithConfiguration: configuration.
   586     context := self context.
   600     context := self context.
   587     context initializeFor: parser.
   601     context initializeFor: parser.
   594 !
   608 !
   595 
   609 
   596 setupSmalltalkGrammarTokenized
   610 setupSmalltalkGrammarTokenized
   597 
   611 
   598     configuration := PPCConfiguration tokenizing.
   612     configuration := PPCConfiguration tokenizing.
   599     configuration arguments name: #PPTokenizedSmalltalkGrammar.
   613     configuration arguments parserName: #PPTokenizedSmalltalkGrammar.
       
   614     configuration arguments scannerName: #PPTokenizedSmalltalkScanner.
   600     configuration arguments profile: profile.
   615     configuration arguments profile: profile.
   601     
   616     
   602     parser := PPSmalltalkGrammar new compileWithConfiguration: configuration.
   617     parser := PPSmalltalkGrammar new compileWithConfiguration: configuration.
   603     context := self context.
   618     context := self context.
   604     context initializeFor: parser.
   619     context initializeFor: parser.
   620     "Created: / 16-05-2015 / 09:44:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   635     "Created: / 16-05-2015 / 09:44:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   621 !
   636 !
   622 
   637 
   623 setupSmalltalkNoopParserTokenized
   638 setupSmalltalkNoopParserTokenized
   624 
   639 
   625     configuration := PPCConfiguration LL1.
   640     configuration := PPCConfiguration tokenizing.
   626     parser := PPCSmalltalkNoopParser new compileWithConfiguration: configuration.
   641     parser := PPCSmalltalkNoopParser new compileWithConfiguration: configuration.
   627     context := PPCContext new.
   642     context := PPCContext new.
   628     context initializeFor: parser.
   643     context initializeFor: parser.
   629     input := sources smalltalkSourcesBig.
   644     input := sources smalltalkSourcesBig.
   630 
   645