I wrote a JSON library
w0rp
devw0rp at gmail.com
Tue May 14 13:23:40 PDT 2013
I have been working on a few improvements to the library. First,
I made a few performance tweaks. Aside from very small (and
therefore hard to describe) tweaks, I made two major improvements.
1. Manual parsing of numbers has been implemented.
2. When the input is a string, the indices and the length are
used instead of the array InputRange functions.
The first one is a dangerous idea, but my unit tests show that at
least what I have tested works. The reasoning behind it is that
before, a string buffer (Appender!string) was created for
numbers, and then one of parse!long or parse!real was chosen
based upon whether or not the parser figured out it was an
integer or not. Now it will read the input into actual numbers as
it goes and then spit out an integer or a floating point number
after it hits the end. You need to put a helmet on, but there's
less allocation along the way. Perhaps this idea could be better
encapsulated at some point with an std.conv function which
accepts a range and returns a tagged union.
The second improvement is actually pretty nice, because I already
wrapped the input range functions in methods anyway, so it was a
simple matter of inserting 'static if ... else' to flip the
string optimisation on. Perhaps it is better in general to wrap
strings in range structs than to rely on std.array's range
functions.
The end result is that I can now cheat at my own benchmark.
---
Ran for 100 runs
std.json : 674 ms
vibe.data.json : 604 ms
json : 548 ms
---
Which I updated slightly to match some function renaming (plus to
correct my earlier embarrassing omission of .msecs) here:
http://pastebin.com/KciFit4b
It's not a complete test of speed, and as always with benchmarks,
mileage will vary.
In addition to these things, I made a few of the property and
function names a little nicer, and generally improved on the
documentation, which currently looks a little like this.
http://www.mediafire.com/?q5lwtj2cc22s1t0 I apologise for my
current lack of hosting. (I plan to correct this at a later date,
perhaps with a website written in D!)
More information about the Digitalmars-d
mailing list