The Computer Language
24.04 Benchmarks Game

regex-redux Pharo Smalltalk program

source code

"* The Computer Language Benchmarks Game
    http://benchmarksgame.alioth.debian.org/
    contributed by Eliot Miranda
    modified by Isaac Gouy *"!


Object subclass: #BenchmarksGame
   instanceVariableNames: ''
   classVariableNames: ''
   poolDictionaries: ''
   category: ''!


!BenchmarksGame class methodsFor: 'private'!

matchPatterns
   ^#(   'agggtaaa|tttaccct'
         '[cgt]gggtaaa|tttaccc[acg]'
         'a[act]ggtaaa|tttacc[agt]t'
         'ag[act]gtaaa|tttac[agt]ct'
         'agg[act]taaa|ttta[agt]cct'
         'aggg[acg]aaa|ttt[cgt]ccct'
         'agggt[cgt]aa|tt[acg]accct'
         'agggta[cgt]a|t[acg]taccct'
         'agggtaa[cgt]|[acg]ttaccct'
   )! !

!BenchmarksGame class methodsFor: 'private'!

substitutionPatterns
   ^#(   #('tHa[Nt]' '<4>')
         #('aND|caN|Ha[DS]|WaS' '<3>')
         #('a[NSt]|BY' '<2>')
         #('<[^>]*>' '|')
         #('\\|[^|][^|]*\\|' '-'))! !


!BenchmarksGame class methodsFor: 'private'!

regexDNA: sequence to: output
   | s size1 size2 translation |
   size1 := sequence size.

   "* remove FASTA sequence descriptions and new-lines *"
   s := sequence copyWithRegex: '>[^\r]*\r|\r' matchesReplacedWith: ''.
   size2 := s size.

   "* regex match *"
   self matchPatterns do: [:each| 
      output 
         nextPutAll: each; space; 
         print: (s occurrencesOfRegex: each); nl
      ]. 

   "* regex substitution *"
   translation := Dictionary new.
   self substitutionPatterns do: [:each| 
      translation at: each first put: each last].

   s := s copyWithRegex: '[', 
         (translation keys asArray fold: [:a :b| a, b]), ']'
      matchesTranslatedUsing: [:l| translation at: l].

   output
      nl;
      print: size1; nl; 
      print: size2; nl; 
      print: s size; nl! !


!BenchmarksGame class methodsFor: 'initialize-release'!

do: n
   self regexDNA: Stdio stdin contents asString to: Stdio stdout! !


!Stream methodsFor: 'benchmarks game'!

nl
   self nextPut: Character lf! !

    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Pharo 10.1.1
Mar 12 2024 13:57:46
Compiler: 5.4.0 20160609


 Fri, 15 Mar 2024 22:30:44 GMT

MAKE:
cp /opt/src/pharo-vm-Linux-x86_64-stable/Pharo11-SNAPSHOT-64bit-aece1b5.image regexredux.pharo_run.image
cp /opt/src/pharo-vm-Linux-x86_64-stable/Pharo11-SNAPSHOT-64bit-aece1b5.changes regexredux.pharo_run.changes
ln -s /opt/src/pharo-vm-Linux-x86_64-stable/Pharo11.0-64bit-aece1b5.sources .
cat Include/pharo/make.st
| prog |

(SystemWindow windowsIn: World
      satisfying: [:w | w model canDiscardEdits])
   do: [:w | w delete].

   "load program to be measured"
prog := Smalltalk getSystemAttribute: 3.
(prog notNil) ifTrue: [prog asFileReference fileIn].

ImageCleaner cleanUpForRelease.
Smalltalk garbageCollect.
SmalltalkImage current snapshot: true andQuit: true.
/opt/src/pharo-vm-Linux-x86_64-stable/pharo --headless regexredux.pharo_run.image Include/pharo/make.st regexredux.pharo
cat Include/pharo/main.st

BenchmarksGame do: (Smalltalk getSystemAttribute: 3) asInteger.!
SmalltalkImage current snapshot: false andQuit: true!



26.62s to complete and log all make actions

COMMAND LINE:
 /opt/src/pharo-vm-Linux-x86_64-stable/pharo --headless regexredux.pharo_run.image Include/pharo/main.st 0 < regexredux-input50000.txt

PROGRAM FAILED 


PROGRAM OUTPUT:

RegexSyntaxError: bad backslash escape
RxParser class>>signalSyntaxException:
[RxParser signalSyntaxException: 'bad backslash escape'] in RxsPredicate class>>forEscapedLetter: in Block: [RxParser signalSyntaxException: 'bad backslas[..]
Dictionary>>at:ifAbsent:
RxsPredicate class>>forEscapedLetter:
RxCharSetParser>>parseEscapeChar
RxCharSetParser>>parseStep
RxCharSetParser>>parse
RxParser>>characterSetFrom:
RxParser>>characterSet
RxParser>>atom
RxParser>>piece
RxParser>>branch
RxParser>>branch
RxParser>>regex
RxParser>>parseStream:
RxParser>>parse:
ByteString(String)>>asRegex
ByteString(String)>>copyWithRegex:matchesReplacedWith:
BenchmarksGame class>>regexDNA:to:
BenchmarksGame class>>do:
UndefinedObject>>DoIt
OCReceiverDoItSemanticScope(OCDoItSemanticScope)>>evaluateDoIt:
OpalCompiler>>evaluate
DoItChunk>>importFor:logSource:
[ :declaration |
		requestor ifNotNil: [
			requestor contents: declaration contents ].
		value := declaration importFor: requestor logSource: logSource  ] in CodeImporter>>evaluate in Block: [ :declaration |...
OrderedCollection>>do:
CodeImporter>>evaluate
[ codeImporter evaluate ] in STCommandLineHandler>>installSourceFile: in Block: [ codeImporter evaluate ]
FullBlockClosure(BlockClosure)>>on:do:
STCommandLineHandler>>handleErrorsDuring:reference: