Levente Uzonyi uploaded a new version of SUnit to project The Trunk:
http://source.squeak.org/trunk/SUnit-ul.72.mcz ==================== Summary ==================== Name: SUnit-ul.72 Author: ul Time: 4 December 2009, 3:49:32 am UUID: d7af06fb-2952-0142-a41d-39b4547ded99 Ancestors: SUnit-ul.71 - speed up TestCase >> allTestSelectors =============== Diff against SUnit-nice.70 =============== Item was changed: ----- Method: TestCase class>>allTestSelectors (in category 'accessing') ----- allTestSelectors + ^(self allSelectors asArray select: [ :each | + (each beginsWith: 'test') and: [ each numArgs isZero ] ]) sort - ^self allSelectors asSortedCollection asOrderedCollection select: [:each | - ('test*' match: each) and: [each numArgs isZero]] ! |
2009/12/4 <[hidden email]>:
> Levente Uzonyi uploaded a new version of SUnit to project The Trunk: > http://source.squeak.org/trunk/SUnit-ul.72.mcz > > ==================== Summary ==================== > > Name: SUnit-ul.72 > Author: ul > Time: 4 December 2009, 3:49:32 am > UUID: d7af06fb-2952-0142-a41d-39b4547ded99 > Ancestors: SUnit-ul.71 > > - speed up TestCase >> allTestSelectors > > =============== Diff against SUnit-nice.70 =============== > > Item was changed: > ----- Method: TestCase class>>allTestSelectors (in category 'accessing') ----- > allTestSelectors > > + ^(self allSelectors asArray select: [ :each | 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' ? 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 implementation will avoid creating 2 extra temporary collections (in #allSelectors and in #select:) > + (each beginsWith: 'test') and: [ each numArgs isZero ] ]) sort > - ^self allSelectors asSortedCollection asOrderedCollection select: [:each | > - ('test*' match: each) and: [each numArgs isZero]] > ! > > > -- Best regards, Igor Stasenko AKA sig. |
2009/12/4 Igor Stasenko <[hidden email]>:
> 2009/12/4 <[hidden email]>: >> Levente Uzonyi uploaded a new version of SUnit to project The Trunk: >> http://source.squeak.org/trunk/SUnit-ul.72.mcz >> >> ==================== Summary ==================== >> >> Name: SUnit-ul.72 >> Author: ul >> Time: 4 December 2009, 3:49:32 am >> UUID: d7af06fb-2952-0142-a41d-39b4547ded99 >> Ancestors: SUnit-ul.71 >> >> - speed up TestCase >> allTestSelectors >> >> =============== Diff against SUnit-nice.70 =============== >> >> Item was changed: >> ----- Method: TestCase class>>allTestSelectors (in category 'accessing') ----- >> allTestSelectors >> >> + ^(self allSelectors asArray select: [ :each | > > 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' ? > > 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 implementation will avoid creating 2 extra temporary collections > (in #allSelectors and in #select:) > But #allSelectors is not #selectors. It includes all superclasses selectors... And it is a Set to avoid duplicates. Nicolas >> + (each beginsWith: 'test') and: [ each numArgs isZero ] ]) sort >> - ^self allSelectors asSortedCollection asOrderedCollection select: [:each | >> - ('test*' match: each) and: [each numArgs isZero]] >> ! >> >> >> > > > > -- > Best regards, > Igor Stasenko AKA sig. > > |
In reply to this post by Igor Stasenko
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. > > |
Free forum by Nabble | Edit this page |