[Glass] Faster Float printing possible?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Feb 8 08:51:02 PST 2017


Hi guys,

The app I am developing is a financial one and in many case I must
serialize via JSON some large series of prices or fundamental data. Many
times these numbers are SmallFloat and the printing to JSON takes quite
some time. See below:

34.1% (15) WAJsonCanvas         >> render:
                                                          31.8% (14)
SmallDouble          >> jsonOn:
|  31.8% (14) WAJsonCanvas         >> binaryFloat:
|     31.8% (14) BinaryFloat          >> printOn:base: [SmallDouble]
|        31.8% (14) BinaryFloat          >> absPrintOn:base: [SmallDouble]
|            9.1% (4) GRUtf8CodecStream    >> nextPut:|            |   4.5%
(2) WriteStream          >> nextPut: [AnsiWriteStream]
|            4.5% (2) BinaryFloat          >> >= [SmallDouble]
|            4.5% (2) Integer              >> * [SmallInteger]
|            |   2.3% (1) Number               >> _retry:coercing:
[SmallInteger]
|            |      2.3% (1) Float                >> _coerce: [SmallDouble]
|            4.5% (2) BinaryFloat          >> timesTwoPower: [SmallDouble]
|            2.3% (1) Float                >> raisedToInteger: [SmallDouble]
|            2.3% (1) Character class      >> digitValue:




Now..this ends up doing:

WAJsonCanvas  >> binaryFloat: aBinaryFloat
  aBinaryFloat printOn: self document stream base: 10

And the implementation of

BinaryFloat >> printOn: aStream base: base
  "Handle sign, zero, and NaNs; all other values passed to absPrintOn:base:"

  self isNaN
    ifTrue: [
      aStream nextPutAll: 'NaN'.
      ^ self ]. "check for NaN before sign"
  self > 0.0
    ifTrue: [ self absPrintOn: aStream base: base ]
    ifFalse: [
      self sign = -1
        ifTrue: [ aStream nextPutAll: '-' ].
      self = 0.0
        ifTrue: [
          aStream nextPutAll: '0.0'.
          ^ self ]
        ifFalse: [ self negated absPrintOn: aStream base: base ] ]


Above implementation is in *squeak-printing. And I know that this package
does not receive much attention and possible gets outdated frequently. I
suspect GemStone may have (at this time?) a faster way to achieve the
above.

Is there something like that I can use with faster times?

Thanks in advance


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20170208/c36776b2/attachment.html>


More information about the Glass mailing list