From 5f6990d74695bf5452d9d5870cf5760628497114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 26 Jul 2020 21:33:49 +0200 Subject: [PATCH] Only start Section's timer if the duration will be used This is a small potential runtime optimization on systems with virtual syscalls, and a significant runtime optimization on systems without. --- src/catch2/internal/catch_section.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/catch2/internal/catch_section.cpp b/src/catch2/internal/catch_section.cpp index 3652daf0..52361584 100644 --- a/src/catch2/internal/catch_section.cpp +++ b/src/catch2/internal/catch_section.cpp @@ -16,7 +16,11 @@ namespace Catch { : m_info( info ), m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) { - m_timer.start(); + // Non-"included" sections will not use the timing information + // anyway, so don't bother with the potential syscall. + if (m_sectionIncluded) { + m_timer.start(); + } } Section::~Section() {