[Pharo-project] [update] #10126
-> Issue 248: SLICE-Mantis-ScaledDecimal-SqNumberParser-Fix-nice.1 -> Issue 295: #testSupplyAnswerUsingRegexMatchOfQuestion fails -> latest collection tests 248 is a collection of fixes (thanks to Nicolas Cellier). Here is the full description: GATHER SOME FIX FROM MANTIS CONCERNING SqNumberParser AND ScaledDecimal ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=6976 This changeSet makes SqNumberParser about twice and up to four times faster than it used to in Float Number crunching. Four improvements were proposed: 1) Inline digitValue when radix <= 10. This is the main gain. 2) Don't test 'NaN' and 'Infinity' in preamble. Test only in exceptional conditions (when no digit were found). 3) hack (aRadix raisedTo: exponent) with base 2 bitShift: arithmetic and use timesTwoPower: a posteriori to avoid some LargePositiveInteger. 4) hack PositionableStream>>position: replace & condition by and: which is inlined by Compiler"! NOTE: I did not load changes for the 3) item I find optimization hackish concerning gradual underflow, for marginal gains... It could eventually enhance greatly reading hex float... You can find it as file SqNumberParser_speedUp_Patch_M6976_nice.1.cs in mantis report. ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=7174 This change set enables a further speed up for number parsing - LargeInteger (like 20 factorial) - Float with large fractionPart (like Float pi). Note that this change introduces selector #isLarge (rather than testing isKindOf: LargePositiveInteger). ------------------------------------------------------------ Additional refactorings for SqNumberParser: 1) avoid using (self readSomethingIfFail: [aBlock]), and replace with (value := self readSomething ifNil: [aBlock]) This is for efficiency (up to +25%) 2) factor repeated code into smaller methods ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=7169 SqNumberParser does not parse a ScaledDecimal with trailing zeros correctly (like 0.50s2). ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=6779 ScaledDecimal readFrom: '5.3' would not answer a ScaledDecimal ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=6976 1.00s2 isLiteral used to answer false. ------------------------------------------------------------ http://bugs.squeak.org/view.php?id=4378 Some ScaledDecimal have more precision than they actually print. They should not use printOn: to storeOn: in this case. ------------------------------------------------------------ | report | report := (String new: 1024) writeStream. report nextPutAll: 'Timing SqNumberParser for some numbers:'; cr. {'0.0'. '0.0001'. '1.2000000'. '3.14159'. '-3.14159'. '314159.276'. '3.14159e10'. '3.14159e-10'. Float pi printString. 'NaN'. '-Infinity'. '1'. '-256'. SmallInteger maxVal printString. 20 factorial printString} do: [:e | | sqBench numBench speedFactor | sqBench := [SqNumberParser parse: e readStream] bench. numBench := [Number readFrom: e readStream] bench. speedFactor := (SqNumberParser on: sqBench) nextNumber / (SqNumberParser on: numBench) nextNumber. report nextPutAll: e , ' ' , sqBench , ' Speed Up factor vs Number readFrom: = x' , (speedFactor roundTo: 0.1) printString; cr]. report contents. 'Timing SqNumberParser for some numbers: 0.0 45454.10917816437 per second. Speed Up factor vs Number readFrom: = x2.9 0.0001 25432.51349730054 per second. Speed Up factor vs Number readFrom: = x2.3 1.2000000 24007.19856028794 per second. Speed Up factor vs Number readFrom: = x2.6 3.14159 23199.5600879824 per second. Speed Up factor vs Number readFrom: = x2.2 -3.14159 22635.6728654269 per second. Speed Up factor vs Number readFrom: = x2.1 314159.276 21928.81423715257 per second. Speed Up factor vs Number readFrom: = x2.4 3.14159e10 14818.03639272146 per second. Speed Up factor vs Number readFrom: = x2.4 3.14159e-10 11181.96360727855 per second. Speed Up factor vs Number readFrom: = x2.7 3.141592653589793 5472.50549890022 per second. Speed Up factor vs Number readFrom: = x1.5 NaN 23603.27606871754 per second. Speed Up factor vs Number readFrom: = x0.4 -Infinity 32998.200359928 per second. Speed Up factor vs Number readFrom: = x0.8 1 81118.776244751 per second. Speed Up factor vs Number readFrom: = x2.7 -256 70116.1767646471 per second. Speed Up factor vs Number readFrom: = x3.2 1073741823 42773.8452309538 per second. Speed Up factor vs Number readFrom: = x3.9 2432902008176640000 16934.01319736053 per second. Speed Up factor vs Number readFrom: = x4.0 -- Marcus Denker -- denker@iam.unibe.ch http://www.iam.unibe.ch/~denker
participants (1)
-
Marcus Denker