[ENH] fastDateAndTimeEquals-brp [su][sm]

stéphane ducasse ducasse at iam.unibe.ch
Thu Sep 23 19:33:33 UTC 2004


can someone with interest in this changes, test and comment.
Then I will push it into 3.8
Thanks

On 23 sept. 04, at 18:20, Brent Pinkney wrote:

> Hi,
>
> Reposting this for 3.8 unstable.
>
> There has been some grumpling about the sluggishness of the 
> DateAndTime implementation.
>
> This enhancement provides a 60% improvement. All DateAndTimeTest SUnit 
> tests are successful.
>
> In the general case, no improvement is possible since DateAndTime 
> instances can
> 	1) be in different time zones
> 	2) has nano second precision.
>
> Fortuntately almost all the DateAndTime, Date, Month, Year, etc 
> instances a user will create will be in the same time zone and have a 
> nanosecond value of 0. In this case we only need to compare the 
> instance variables SmallIntegers
>
> DateAndTime now anticipates this common special case.
>
> Results
> -------
> dt :=DateAndTime now.
>
> utcs := (1 to: 900) collect: [ :i | DateAndTime now + ((i * 10) 
> nanoSeconds) ].
> 100 timesRepeat: [ utcs := utcs, dt ].
> utcs := utcs shuffled.
>
> [ 1000 timesRepeat: [ utcs do: [ :x | x = dt ]] ] timeToRun.
>
> Before:
> #(7403 7418 7419 7410 7393) average asInteger ==> 7408 milliseconds.
>
> After:
> #(2979 2968 2971 2991 2966) average asInteger ==> 2975 milliseconds.
>
> Improvement:
> ( 1 - ( 2975/7408) ) asFloat ==> 0.598407127429806 ==> 60%
>
> Notes. The old Squeak Date class used a SmallInteger instance variable 
> to record the julian day offset.
> The new Date class is more sophisticated, but we can get a rough idea 
> of how much faster this used to be:
>
> dates := (1 to: 900) collect: [ :i | (Date today + ((i * 10) days))  ].
> 100 timesRepeat: [ dates := dates, (Date today) ].
> dates := dates shuffled.
> [ 1000 timesRepeat: [ dates do: [ :x | x julianDayNumber = dt 
> julianDayNumber ]]] timeToRun
>
> #(565 565 566 564 564) average asInteger ==> 564
>
> We are slower by a factor of 5.
>
> Cheers
>
> Brent<fastDateAndTimeEquals-brp.3.cs.gz>




More information about the Squeak-dev mailing list