Cache std::ostringstream between assertions.

This is not thread safe, but I think that was already true of Catch.
The construction/destruction of the std::ostringstream is where the
vast majority of time is spent per assertion.  A simple test of
100000000 CHECK()s is reduced from around 60s to 7.4s
This commit is contained in:
Neal Coombes
2017-06-23 11:31:17 -05:00
committed by Martin Hořeňovský
parent a6cdcd43aa
commit 396ecf6021
2 changed files with 13 additions and 6 deletions

View File

@@ -47,7 +47,7 @@ namespace Catch {
template<typename T>
ResultBuilder& operator << ( T const& value ) {
m_stream.oss << value;
m_stream().oss << value;
return *this;
}
@@ -80,7 +80,12 @@ namespace Catch {
private:
AssertionInfo m_assertionInfo;
AssertionResultData m_data;
CopyableStream m_stream;
static CopyableStream &m_stream()
{
static CopyableStream s;
return s;
}
bool m_shouldDebugBreak;
bool m_shouldThrow;