Smalltalk SLOP/SMOP benchmarks: A follow-up 
Author Message
 Smalltalk SLOP/SMOP benchmarks: A follow-up

This is a followup to my benchmark post.

Remember how slow the sorting of strings was in ParcPlace VisualWorks?
Well, the engineers at ParcPlace have discovered where the bottleneck is.  
If you do a lot of string sorting, you'll want to use this trick.
Why this isn't the default behavior, I don't know...

In your sorting code, instead of:

        aSet asSortedCollection

instead write:

        aSet asSortedCollection: [:a :b | (a trueCompare: b) <= 0]

This will cause the trueCompare: method to be used instead of the
compare: method.  The trueCompare: method tries a primitive first, so for
most Strings, the processing is done in the VM, for a radical increase
in speed (almost 3x). The strange math (<= 0) is due to the fact that
trueCompare: returns -1 or 0 or +1, depending on whether the
left argument is lexically less than, equal, or greater than
the right argument, respectively.

This "fix" puts ParcPlace at the top of the sorting heap (pardon
the sordid metaphor), but it strikes me as something that should
be fixed in the base classes, not hacked into every program.

Obviously, this code is also non-portable from Smalltalk to Smalltalk,
and in defense of the SLOP/SMOP benchmarks, they DID compile perfectly
on every platform.  They wouldn't if we changed the benchmark to use
this method.

Anybody from ParcPlace want to comment on why this is, or needs to be,
the way it is?

Cheers,
Jim



Sun, 29 Jun 1997 11:20:11 GMT  
 Smalltalk SLOP/SMOP benchmarks: A follow-up

Quote:

>This is a followup to my benchmark post.

>Remember how slow the sorting of strings was in ParcPlace VisualWorks?
>Well, the engineers at ParcPlace have discovered where the bottleneck is.  
>If you do a lot of string sorting, you'll want to use this trick.
>Why this isn't the default behavior, I don't know...

>In your sorting code, instead of:

>    aSet asSortedCollection

>instead write:

>    aSet asSortedCollection: [:a :b | (a trueCompare: b) <= 0]

>This will cause the trueCompare: method to be used instead of the
>compare: method.  The trueCompare: method tries a primitive first, so for
>most Strings, the processing is done in the VM, for a radical increase
>in speed (almost 3x). The strange math (<= 0) is due to the fact that
>trueCompare: returns -1 or 0 or +1, depending on whether the
>left argument is lexically less than, equal, or greater than
>the right argument, respectively.

>This "fix" puts ParcPlace at the top of the sorting heap (pardon
>the sordid metaphor), but it strikes me as something that should
>be fixed in the base classes, not hacked into every program.

If you would look at the comment in the methods "< > <= >=" in class String
you would see that these operators are designed to compare strings in a
collating sequence, i.e. upper and lower case are the same, this is not a
lexical comparison.  Changing these methods might break other methods.

But, this points out a definition problem.  Smalltalk needs some clearly named
comparison operators, the behavior definitions of "< ..." is not obvious from
their names.   A good issue for a standards committee.

Quote:
>Obviously, this code is also non-portable from Smalltalk to Smalltalk,
>and in defense of the SLOP/SMOP benchmarks, they DID compile perfectly
>on every platform.  They wouldn't if we changed the benchmark to use
>this method.

Now, If you want your compiler to run faster, and many applications that
use Symbol, then file in the following.

!Symbol class methodsFor: 'accessing'!

findInterned: aString
        " If aString has been interned (into a Symbol),
        answer the Symbol, otherwise answer nil. "

        | v charCode stringSize |
        (stringSize := aString size) = 1 ifTrue:
                [(charCode := (aString at: 1) asInteger) < 256
                        ifTrue:
                                [^SingleCharSymbols at: charCode + 1]].
        v := self table at: aString stringhash \\ self table size + 1.
        1 to: v size do:
                [:i | | test |
                ((test := v at: i) isSymbol
                                and: [stringSize = test size
                                and: [(aString trueCompare: test) = 0]])
                        ifTrue: [^test]].
        ^nil! !

--
Terry Raymond                          Telephone: 1-401-846-6144



Tue, 01 Jul 1997 08:51:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Free Smalltalk Tools Followup

2. Factorial-Benchmark with Dolphin Smalltalk

3. Smalltalk MT Performance on David Buck / VW / STIC Benchmarks

4. Smalltalk MT Performance on David Buck / VW / STIC Benchmarks

5. Smalltalk vs C vs C++ benchmark results

6. Where to find up to date Smalltalk benchmarks?

7. Smalltalk and Java Benchmarks

8. Smalltalk Server Benchmarks

9. Benchmarks for Smalltalk systems

10. Smalltalk benchmarks

11. Smalltalk benchmarks

12. Any suggestions on a simple Smalltalk benchmark?

 

 
Powered by phpBB® Forum Software