[squeak-dev] The Trunk: ToolBuilder-Kernel-mt.125.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Tue Jul 16 11:36:06 UTC 2019


Here are two other faster versions:

| p n |
p := 'WKD'
n := 'WeakIdentityKeyDictionary'.

[ | isMatch lookupIndex |
isMatch := true.
lookupIndex := 0.
1 to: p size do: [:charIndex | | char |
char := p at: charIndex.
isMatch ifTrue: [
lookupIndex := (n findString: char asString startingAt: lookupIndex+1 caseSensitive: true).
isMatch := lookupIndex > 0]].
isMatch 
] bench
'3,050,000 per second. 328 nanoseconds per run.'


[ | isMatch lookupIndex |
isMatch := true.
lookupIndex := 0.
1 to: p size do: [:charIndex | 
isMatch := isMatch and: [0 <
(lookupIndex := n
findString: (p at: charIndex) asString
startingAt: lookupIndex+1 caseSensitive: true)]].
isMatch
] bench
 '3,080,000 per second. 325 nanoseconds per run.'

This is fun. :-D

Best,
Marcel
Am 16.07.2019 09:11:29 schrieb Marcel Taeumel <marcel.taeumel at hpi.de>:
Hi Kjell,

here are more Benchmarks:  

| p n |
p := 'WKD'
n := 'WeakIdentityKeyDictionary'.

[ | first stillAMatch |
first := stillAMatch := true.
(0 < (p inject: 1 into: [:i :char | 
stillAMatch ifFalse: [0] ifTrue: [
(n findString: char asString startingAt: i caseSensitive: true)
in: [:i1 | stillAMatch := (first ifTrue: [i = i1] ifFalse: [i < i1]). first := false];
yourself]] ) ) & stillAMatch
] bench
'1,960,000 per second. 510 nanoseconds per run.'

[ | first i |
first := true.
i := 0.
p allSatisfy: [:char |
i := i + 1. 
(n findString: char asString startingAt: i caseSensitive: true)
in: [:i1 | first ifTrue: [first := false. i = i1] ifFalse: [i < i1] ] ]
] bench  
'1,770,000 per second. 564 nanoseconds per run.'


[((n select: [:c | c isUppercase and: [p includes: c]]) indexOfSubCollection: p) > 0] bench
'928,000 per second. 1.08 microseconds per run.'

[((n select: [:c | c isUppercase and: [p includes: c]]) findString: p) > 0] bench
'897,000 per second. 1.11 microseconds per run.'

[((n select: [:c | p includes: c]) indexOfSubCollection: p) > 0] bench
'493,000 per second. 2.03 microseconds per run.'

[((n select: [:c | p includes: c]) findString: p) > 0] bench
'495,000 per second. 2.02 microseconds per run.'

So, your solution is the fastest. I still wonder why I would need that final "& stillAMatch" at the end? And isn't "i = i1" rather "i1 = 1" and "i < i1" rather "i1 > 0"? And why isn't the starting index increasing? Did I make a copy-and-paste mistake? :-) The pattern 'WWK' should check for two separate $W's. Also, Squeak's cascade is slower than using a temp.

This is the current version:

| p n |
p := 'WKD'
n := 'WeakIdentityKeyDictionary'.

[ | first stillAMatch i1 |
first := stillAMatch := true.
0 < (p inject: 0 into: [:i :char | 
stillAMatch ifFalse: [0] ifTrue: [
i1 := (n findString: char asString startingAt: i+1 caseSensitive: true).
stillAMatch := (first ifTrue: [i1 = 1] ifFalse: [i1 > 0]).
first := false.
i1]] ) 
] bench
'2,390,000 per second. 419 nanoseconds per run.'

Best,
Marcel
Am 15.07.2019 21:17:50 schrieb Kjell Godo <squeaklist at gmail.com>:
?


( ( eachName select:[ :c | c isUpperCase and:[ pattern includes: c ] ] )
     indexOfSubCollection: pattern 
) > 0


0 < ( ( eachName select:[ :c | pattern includes: c ] ] ) indexOfSubCollection: pattern )




?

On Mon, Jul 15, 2019 at 10:22 tim Rowledge <tim at rowledge.org [mailto:tim at rowledge.org]> wrote:

I really like making the search tool more helpful; thnak you.

It reminds me that many (many...) years ago a colleague at ParcPlace did a quick 'soundex' search implementation. It was fairly simple and seemed to work quite well for those times when you don't know the exact speliiiing ov yur thngg. It might be an interesting avenue to wander down.

tim
--
tim Rowledge; tim at rowledge.org [mailto:tim at rowledge.org]; http://www.rowledge.org/tim [http://www.rowledge.org/tim]
Strange OpCodes: CLOUT: Call Long-distance On Unused Telephone



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190716/9f03b365/attachment.html>


More information about the Squeak-dev mailing list