Curt Arnold wrote:

The benchmark, like all benchmarks, is synthetic. This one assumes that a log stream is allocated for each logging request which I would assume is very atypical. I'd expect that most of the cost is in the construction of std::basic_stringbuf, but would love to see a profile on it. The initialization cost of std::basic_ostream itself appears to be vanishingly small (copy a pointer). A streambuf that did not allocate 512 characters on construction, but only when the first characters were logged would likely cut things way way down.

I'm sorry, I appear to have wasted my time and yours. When you asked for construction metrics I had assumed you meant for your implementation. With your current scheme there would be no way to avoid the cost of instantiating std::basic_stringbuf, as it's not a templated parameter.


As for the typical use, I found with log4cpp it was wise to just use a new stream each time. This was partly because their design didn't have much efficiency for the case where you reused the stream, but it was also to avoid being effected by changes in stream state from other logging events. In order to ensure encapsulation, it is just easier to get a new stream each time. One could avoid this using io state savers as I alluded to earlier, but that seems like a fair bit of work. It would also seem like you'd have a lot of buffers lying around chewing up memory.

You're thinking in a different paradigm than what I was accustomed to with log4cpp, so I need to reevaluate these use patterns.

--Chris

Reply via email to