[Glass] Faster Float printing possible?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Feb 8 11:59:57 PST 2017


On Wed, Feb 8, 2017 at 3:31 PM, Dale Henrichs via Glass <
glass at lists.gemtalksystems.com> wrote:

> 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,
>

Where is Martin when we need him?? hahahahahhaa


> 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 ...
>

Thanks Dale. That indeed gives me like .. around 2x performance
improvement. As for the results, for JSON it looks like correct. But I
would love to hear if Martin has something else to comment on.

Cheers,


> 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 listGlass at lists.gemtalksystems.comhttp://lists.gemtalksystems.com/mailman/listinfo/glass
>
>
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>
>


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


More information about the Glass mailing list