List Info

Thread: Faster RE low-haning fruit




Faster RE low-haning fruit
country flaguser name
Switzerland
2007-09-25 01:48:00
Oscar Nierstrasz reported a regex-intensive script that is
10 times 
slower in Smalltalk than in Ruby.

This was particularly low hanging fruit: Regex objects are
actually no 
different from strings, simply they are cached because they
are created 
read-only.  So, we can extend the caching to any read-only
string 
(including a String literal).  This removes the need to send
asRegex to 
literals -- only when using a variable as the regular
expression that 
should be necessary.

Before:

st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'a.c'
~ 'abc' ] ]
2200
st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'abc'
~ 'a.c' ] ]
2523
st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'abc'
~ ##('a.c' 
asRegex) ] ]
1666

After:

st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'a.c'
~ 'abc' ] ]
1590
st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'abc'
~ 'a.c' ] ]
1732
st> Time millisecondsToRun: [ 100000 timesRepeat: [ 'abc'
~ ##('a.c' 
asRegex) ] ]
1609

(Oscar, another change to do in your script is to move
temporaries 
outside whileXxxx: because that prevents inlining the
block).

Paolo

_______________________________________________
help-smalltalk mailing list
help-smalltalkgnu.org

http://lists.gnu.org/mailman/listinfo/help-smalltalk

  
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )