Comparison of ScaledDecimals is slow comparative to other numeric types, e.g.
"Integer = Integer"
Time microsecondsToRun: [100000 timesRepeat: [1=1]]. "1,859"
Time microsecondsToRun: [100000 timesRepeat: [1=2]]. "1,831"
"Float = Float"
Time microsecondsToRun: [100000 timesRepeat: [1.0=1.0]]. "3,060"
Time microsecondsToRun: [100000 timesRepeat: [1.0=2.0]]. "3,121"
"ScaledDecimal = ScaledDecimal"
Time microsecondsToRun: [100000 timesRepeat: [1.0s2=1.0s2]]. "80,338"
Time microsecondsToRun: [100000 timesRepeat: [1.0s2=2.0s2]]. "76,505"
"Integer = Float"
Time microsecondsToRun: [100000 timesRepeat: [1=1.0]]. "31,170"
Time microsecondsToRun: [100000 timesRepeat: [1=2.0]]. "31,772"
"Integer = ScaledDecimal"
Time microsecondsToRun: [100000 timesRepeat: [1=1.0s2]]. "165,616"
Time microsecondsToRun: [100000 timesRepeat: [1=2.0s2]]. "176,070"
The slowness looks to be largely down to the creation of an intermediate ScaledDecimal in the subtraction operation in ArithmeticValue>>#= .
Performance can be improved (5x or greater) by implementing equalToScaledDecimal: in the ArithmeticValue hierarchy (similar to equalToInteger: etc.) and comparing the ScaledDecimal by its Fraction.
I can submit a pull request for this if acceptable.
Comparison of ScaledDecimals is slow comparative to other numeric types, e.g.
The slowness looks to be largely down to the creation of an intermediate ScaledDecimal in the subtraction operation in
ArithmeticValue>>#=
.Performance can be improved (5x or greater) by implementing
equalToScaledDecimal:
in the ArithmeticValue hierarchy (similar toequalToInteger:
etc.) and comparing the ScaledDecimal by its Fraction.I can submit a pull request for this if acceptable.