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
Pharo8.0.0 build: 1122, commit: bbcdf97
Sun, 10 May 2020 04:16:18 GMT
MAKE:
cp /opt/src/pharo64-linux-stable/Pharo8.0.0-0-64bit-bbcdf97.image regexredux.pharo_run.image
cp /opt/src/pharo64-linux-stable/Pharo8.0.0-0-64bit-bbcdf97.changes regexredux.pharo_run.changes
ln -s /opt/src/pharo64-linux-stable/Pharo8.0-32bit-bbcdf97.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: [FileStream fileIn: prog].
ImageCleaner cleanUpForRelease.
Smalltalk garbageCollect.
SmalltalkImage current snapshot: true andQuit: true.
/opt/src/pharo64-linux-stable/pharo -headless regexredux.pharo_run.image Include/pharo/make.st regexredux.pharo 2>/dev/null
cat Include/pharo/main.st
BenchmarksGame do: (Smalltalk getSystemAttribute: 3) asInteger.!
SmalltalkImage current snapshot: false andQuit: true!
35.01s to complete and log all make actions
COMMAND LINE:
/opt/src/pharo64-linux-stable/pharo -headless regexredux.pharo_run.image Include/pharo/main.st 0 < regexredux-input50000.txt
PROGRAM FAILED
PROGRAM OUTPUT:
pthread_setschedparam failed: Operation not permitted
This VM uses a separate heartbeat thread to update its internal clock
and handle events. For best operation, this thread should run at a
higher priority, however the VM was unable to change the priority. The
effect is that heavily loaded systems may experience some latency
issues. If this occurs, please create the appropriate configuration
file in /etc/security/limits.d/ as shown below:
cat <<END | sudo tee /etc/security/limits.d/pharo.conf
* hard rtprio 2
* soft rtprio 2
END
and report to the pharo mailing list whether this improves behaviour.
You will need to log out and log back in for the limits to take effect.
For more information please see
https://github.com/OpenSmalltalk/opensmalltalk-vm/releases/tag/r3732#linux
[31mRegexSyntaxError: bad backslash escape
[0mRxParser class>>signalSyntaxException:
[ RxParser signalSyntaxException: 'bad backslash escape' ] in RxsPredicate class>>forEscapedLetter: in Block: [ RxParser signalSyntaxException: 'bad backslash e...etc...
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
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 ]
BlockClosure>>on:do:
STCommandLineHandler>>handleErrorsDuring:reference:
STCommandLineHandler>>installSourceFile:
[0m