[Issue 5548] Efficient std.conv.to conversions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 1 08:26:23 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=5548


Orvid King <blah38621 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |blah38621 at gmail.com
         Resolution|WONTFIX                     |


--- Comment #3 from Orvid King <blah38621 at gmail.com> 2013-11-01 08:26:19 PDT ---
After a bit of testing, std.format.fomatValue is not a valid alternative to
having std.conv.to provide overloads that accept an output buffer. The reason
for this is simple, the following code is 3x slower than simply using
to!string(int):


auto toStr = benchmark!(() {
    import std.format;
    import std.range : Appender;

    auto ret = Appender!string();
    auto fmt = FormatSpec!char("%s");
    ret.reserve(4096);
    for (auto i = 0; i < ObjectCount * 11; i++)
    {
        ret.formatValue(i, fmt);
        ret.clear();
    }
})(1);

writefln("Took %s ms (%s) to serialize 100k SimpleObjects with an average
payload of %s bytes (%s).", res[0].msecs, toStr[0].msecs,
cast(real)totalPayload / ObjectCount, totalPayload);


In my tests where ObjectCount was 100k, it takes 400ms for to!string(int) to
create all the strings, and 1100ms for formatValue to do the same.
formattedWrite is even worse, 1500ms. In my current implementation of a dynamic
JSON (de)serializer, more than half of my time is eaten up by converting
integers to strings when performing deserialization. I use a pre-allocated
output range as the destination, so I know I'm not doing any allocations within
my code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list