The Computer Language
24.11 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: 'benchmarks game'!


!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 12.0.0
Pharo-12.0.0+SNAPSHOT.build.1507.sha.
a4f8da8972214b9c9c39c33e826394a109911041 (64 Bit)

Compiler: 5.4.0 20160609


 Wed, 29 May 2024 02:59:47 GMT

MAKE:
cp /opt/src/pharo-vm-Linux-x86_64-stable/Pharo12.0-SNAPSHOT-64bit-a4f8da8.image regexredux.pharo_run.image
cp /opt/src/pharo-vm-Linux-x86_64-stable/Pharo12.0-SNAPSHOT-64bit-a4f8da8.changes regexredux.pharo_run.changes
ln -s /opt/src/pharo-vm-Linux-x86_64-stable/Pharo12.0-64bit-a4f8da8.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!



29.46s 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 |
		value := declaration importFor: nil 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: