|
Boost : |
Subject: [boost] [iostreams] null_sink slower than array_sink
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2011-08-12 15:12:39
I was thinking about using boost::iostreams in place of my own 'array stream', but was surprised by the poor performance.
When doing RPC calls, I often use the following pattern:
a) calculate buffer space required to serialize arguments
b) allocate buffer space
c) serialize into buffer
I use a stream type with an interface of write(),read(), putc(), getc() etc similar to iostreams.
In doing some basic tests serializing a struct I get the following numbers:
stringstream: 2.4e6 times/sec
stream<array_sink>: 3.2e6 times/sec
stream<null_sink>: 1.5e6 times/sec
mystream<char*>: 8.7e6 times/sec (fixed size array)
mystream<size_t>: 1.07e7 times/sec (similar to null_sink, but tracks bytes written)
Perhaps this is the difference between polymorphic and static method calls?
In any case, there is no reason for stream<null_sink> to take twice as long as array_sink as there are no memory copies, all write should be no-ops.
It would probably be useful to add a size_sink that can be used to track the number of bytes written and thus avoid dynamically resizing buffers.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk