mirror of
https://github.com/catchorg/Catch2.git
synced 2025-12-19 08:32:11 +01:00
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:
committed by
Martin Hořeňovský
parent
a6cdcd43aa
commit
396ecf6021
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user