[squeak-dev] The Trunk: SUnit-ul.72.mcz

Levente Uzonyi leves at elte.hu
Fri Dec 4 15:56:09 UTC 2009


On Fri, 4 Dec 2009, Igor Stasenko wrote:

> Some nitpicking :)
>
> Levente, why sending #asArray necessary here?
> If method is expected to return an array, then why not just put it at
> end 'sort asArray' ?
>

The idea is that #allSelectors returns an IdentitySet which does not 
understand #sort, but arrays do. Selecting from an Array is faster 
than from an IdentitySet, so converting it to an array before selecting 
is faster than selecting and then converting.

> Oh, and if you want to make it really fast then it could be done
> something like this:
>
> | selectors |
> selectors := SortedCollection new.
> self selectorsDo: [:each |
>   ((each beginsWith: 'test') and: [ each last ~= $: ]) ifTrue: [
> methods add: each ] ].
> ^ selectors asArray

This is a typical misuse of SortedCollection IMO. SortedCollection ensures 
that it's elements are sorted. In this case the sorted state is kept after 
each #add: which is achieved by insertion sort. For n elements that 
gives O(n*n) runtime instead of O(n*log(n)). And I consider Array >> 
#sort (mergesort) generally faster than #asSortedCollection and friends 
(quicksort).

>
> this implementation will avoid creating 2 extra temporary collections
> (in #allSelectors and in #select:)
>

Anyway, this was the fastest I could come up without reimplementing 
#allSelectors in #allTestSelectors. This implementation is 3x as fast as 
the previous version when running all tests, saving 20 seconds on my pc 
in this case.


Levente

>
>
> -- 
> Best regards,
> Igor Stasenko AKA sig.
>
>



More information about the Squeak-dev mailing list