[ENH] fastDateAndTimeEquals-brp [su][sm]
Brent Pinkney
brent.pinkney at aircom.co.za
Thu Sep 23 16:20:15 UTC 2004
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fastDateAndTimeEquals-brp.3.cs.gz
Type: application/x-gzip
Size: 544 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040923/deeed452/fastDateAndTimeEquals-brp.3.cs.bin
More information about the Squeak-dev
mailing list
|