[Glass] Faster Float printing possible?

Dale Henrichs via Glass glass at lists.gemtalksystems.com
Wed Feb 8 10:31:10 PST 2017


Mariano,

Float>>asString is implemented as a primitive and you could probably use 
that call just about anywhere you want ... I am not a floating point 
guy, so I cannot comment on where you will see differences in the output 
strings (if any at all) and of course I don't know how important 
precision is when you are passing around json ...

Dale


On 02/08/2017 08:51 AM, Mariano Martinez Peck via Glass wrote:
> 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
>
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass

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


More information about the Glass mailing list