[squeak-dev] The Trunk: Kernel-mt.1411.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Oct 8 07:02:16 UTC 2021


Marcel Taeumel uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-mt.1411.mcz

==================== Summary ====================

Name: Kernel-mt.1411
Author: mt
Time: 27 August 2021, 8:38:24.862421 am
UUID: e7c0282d-0324-9342-bd98-477a1ef9a696
Ancestors: Kernel-mt.1410

Move the #round(Up|Down)To: changes down to Integer to not slow-down rounding for Float and Fraction. This also speeds it up a tiny bit more because it is now "inlined" without the extra send to #round(Up|Down)ToInteger:.

Thanks to Levente (ul) for the suggestion! (http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-August/216272.html)

14x speed up of #roundTo: using the same strategy.

[65 roundUpTo: 64] bench
AFTER '31,000,000 per second. 32.2 nanoseconds per run. 0 % GC time.'
BEFORE '2,120,000 per second. 472 nanoseconds per run. 0.73985 % GC time.'

=============== Diff against Kernel-eem.1408 ===============

Item was added:
+ ----- Method: Integer>>roundDownTo: (in category 'truncation and round off') -----
+ roundDownTo: aNumber 
+ 	"Overwritten to speed-up integer rounding via modulo instead of using intermediate fractions."
+ 
+ 	aNumber isInteger ifFalse: [^ super roundDownTo: aNumber].
+ 	^ self - (self \\ aNumber)!

Item was added:
+ ----- Method: Integer>>roundTo: (in category 'truncation and round off') -----
+ roundTo: aNumber 
+ 	"Overwritten to speed-up integer rounding via modulo instead of using intermediate fractions."
+ 
+ 	| rem |
+ 	aNumber isInteger ifFalse: [^ super roundUpTo: aNumber].
+ 
+ 	(rem := self \\ aNumber) = 0 ifTrue: [^ self].
+ 	^ rem < (aNumber // 2)
+ 		ifTrue: ["round down" self - rem]
+ 		ifFalse: ["round up" self + aNumber - rem]!

Item was added:
+ ----- Method: Integer>>roundUpTo: (in category 'truncation and round off') -----
+ roundUpTo: aNumber 
+ 	"Overwritten to speed-up integer rounding via modulo instead of using intermediate fractions."
+ 
+ 	| rem |
+ 	aNumber isInteger ifFalse: [^ super roundUpTo: aNumber].
+ 	^ (rem := self \\ aNumber) ~= 0
+ 		ifTrue: [self + aNumber - rem]
+ 		ifFalse: [self]!



More information about the Squeak-dev mailing list