PackageDescription: SYSMOD-LargeIntegerFastUp
SYSMOD - Large Integer Fast UpLast published: February 2, 2007 by 'nice'
Defines 0 Classes
Extends 2 Classes
This is a system modification aimed at speeding up LargeInteger arithmetic.
Only contains a new definition of #bitAt: by now.
super bitAt: is based on bitShift: and bitAnd: operations and will create useless intermediary LargeInteger
This is a donation.
Can you please include in an official image?
-----------------------------------------------------------------------
Thanks to Martin McClure for pointing bug due to not using two-complement in LargeNegativeInteger
and to Eliot Miranda for speeding up the loops
-----------------------------------------------------------------------
Note: speed up for LargePositiveInteger is about a factor of 50.
Note: this is not that obvious for LargeNegativeInteger speed factor is less than 30%
but could be optimized with a lowBit primitive
It has been tested with following code.
(first rename LargePositiveInteger and LargeNegativeInteger bitAt: as nicolasBitAt:)
| seq |
seq := ((LargePositiveInteger allInstances asSet collect: [:each| each
negated])
select: [:each| each class ~~ SmallInteger])
asSortedCollection asArray.
1 to: seq size do:
[:i| | lni | lni := seq at: i. 1 to: lni digitLength * 8 do: [:j| (lni
bitAt: j) ~= (lni nicolasBitAt: j) ifTrue: [self halt]]].
(Time microsecondsToRun: [1 to: seq size do: [:i| | lni | lni := seq at: i.
1 to: lni digitLength * 8 do: [:j| lni bitAt: j]]])
-> (Time microsecondsToRun: [1 to: seq size do: [:i| | lni | lni := seq at:
i. 1 to: lni digitLength * 8 do: [:j| lni nicolasBitAt: j]]])
Timing in my VW7.3.1:
220022->152262
227211->151054
218808->167183
Seems bug-free and faster even for negative integers