[squeak-dev] The Inbox: Kernel-mt.1409.mcz
leves at caesar.elte.hu
Thu Aug 26 20:44:19 UTC 2021
On Thu, 26 Aug 2021, commits at source.squeak.org wrote:
> A new version of Kernel was added to project The Inbox:
> ==================== Summary ====================
> Name: Kernel-mt.1409
> Author: mt
> Time: 26 August 2021, 11:43:29.370208 am
> UUID: 833c07c9-93d9-834e-8e94-59c6a1e941bc
> Ancestors: Kernel-eem.1408
> 8x speed up in #roundUpTo: and #roundDownTo: for integer arguments due to avoiding the creation of intermediate fractions, which also avoids extra GC time.
> Thanks to Stephan (stlu) for the idea!
> [65 roundUpTo: 64] bench
> AFTER '39,500,000 per second. 25.3 nanoseconds per run. 0 % GC time.'
> BEFORE '5,180,000 per second. 193 nanoseconds per run. 1.67966 % GC time.'
> [65 roundDownTo: 64] bench
> AFTER '45,900,000 per second. 21.8 nanoseconds per run. 0 % GC time.'
> BEFORE '5,590,000 per second. 179 nanoseconds per run. 2.29908 % GC time.'
> Needs testing and review. Known issue: "65.0 roundUpTo: 64" now returns "128.0" but used to return "128".
It's a nice idea, but IMO the new methods should only be used with integer
For non-integers like Float and Fraction, I measured ~1.5x slowdown
compared to the original method.
So, IMO Number >> #roundDownTo: should stay as it is and Integer needs
a new >> #roundDownTo::
aNumber isInteger ifFalse: [ ^super roundDownTo: aNumber ].
^self - (self \\ aNumber)
Same goes for #roundUpTo:.
That way the known issue wouldn't be an issue either. (Btw, I think the
roundUpTo: method is missing from the commit.)
More information about the Squeak-dev