|
|
|
|
|
by byroot
527 days ago
|
|
> I should point out that other Oj modes perform much better than the JSON gem Which modes are that? https://github.com/ohler55/oj/blob/develop/pages/Modes.md#oj... I tried: Oj.dump(obj, mode: :strict)
and a few others and none seemed faster than `json 2.9.1` on the benchmarks I use.Edit: Also most of these mode simply aren't correct in my opinion: >> Oj.dump(999.9999999999999, { mode: :compat })
=> "999.9999999999999"
>> Oj.dump(999.9999999999999, { mode: :strict })
=> "1000"
|
|
The callback parsers (Saj and Scp) also show a performance advantage as does the most recent Oj::Parser.
As for the dumping of floats that are at the edge of precision (16 places), Oj does round to to 15 places if the last 4 of a 16 digit float is "0001" or "9999" if the float precision is not set to zero. That is intentional. If that is not the desired behavior and the Ruby conversion is preferred then setting the float precision to zero will not round. You picked the wrong options for your example.
I would like to say that the core json has a come a very long way since Oj was created and is now outstanding. If the JSON gem had started out where it is now I doubt I would have bothered writing Oj.