Closed kusano closed 2 years ago
Thanks for your PR! LGTM.
For your performance concern, I tried running a simple benchmark as follows:
% Common Setup
> Input = [123.0 || X<-lists:seq(1, 100000)].
> Json = jsone:encode(Input).
% `master` branch
> timer:tc(fun jsone:decode/1, [Json]).
{66039, % 66ms
[123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001,
123.00000000000001,123.00000000000001,123.00000000000001|...]}
% PR branch
18> timer:tc(fun jsone:decode/1, [Json]).
{65655, % 65ms
[123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0,
123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0,
123.0,123.0,123.0,123.0,123.0,123.0,123.0,123.0|...]}
There are no significant performance changes. So I think it's okay to merge this PR.
Note that I'll release the next version including this patch within this month.
Before:
After:
Although floating point numbers may have errors, numbers which can be represented without errors should be treated without errors. This patch reduce floating point errors by avoiding the use of decimals.
In spite of that 123000000000000000000 > 253, 123000000000000000000 can be exactly represented in IEEE 754 format since it can be divided by 2 many times.
My concern is performance. Division may be slower than multiplication.
My coworker wrote this patch and he has agreed to post it here.