From b3c75be5e0347078af16d260b197d49ef363729d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 22 Feb 2025 13:40:11 +0100 Subject: [PATCH] QTimeZone::utc(): micro-optimize it QTimeZone::utc() goes through the QTimeZone(int) constructor, passing 0 to it. That in turn calls the QUtcTimeZonePrivate(int) constructor, which ends up matching the zero offset and doing some string comparisons. I think we can bypass this mechanism and simply have QTimeZone::utc() create a QUtcTimeZonePrivate and set it. Compare the following results for tst_QTimeZone::utc benchmark as built on a machine with: Config: Using QtTest library 6.10.0, Qt 6.10.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 14.2.1 20250207), arch unknown Before: 36.708812 nsecs per iteration (total: 36,708,776, iterations: 999999) 169.024518 CPU cycles per iteration, 4,6 GHz (total: 169,024,349, iterations: 999999) 601.286607 instructions per iteration, 3,557 instr/cycle (total: 601,286,006, iterations: 999999) 139.051610 branch instructions per iteration, 3,79 G/sec (total: 139,051,471, iterations: 999999) After: 29.204813 nsecs per iteration (total: 29,204,784, iterations: 999999) 129.981345 CPU cycles per iteration, 4,45 GHz (total: 129,981,216, iterations: 999999) 408.260941 instructions per iteration, 3,141 instr/cycle (total: 408,260,533, iterations: 999999) 85.047524 branch instructions per iteration, 2,91 G/sec (total: 85,047,439, iterations: 999999) Relative Delta: before after improvement nsecs 36.7 29.2 1.26x cycles 169.0 130.0 1.30x instr. 601.3 408.0 1.47x branch 139.1 85.0 1.63x Change-Id: Ic6fe605a3c6a83096315e2cb4309b9f67e83bccc Reviewed-by: Thiago Macieira Reviewed-by: Milian Wolff Reviewed-by: Edward Welbourne --- src/corelib/time/qtimezone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index a23b1e4c9e7..1da2e037c70 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -1455,7 +1455,7 @@ QTimeZone QTimeZone::systemTimeZone() */ QTimeZone QTimeZone::utc() { - return QTimeZone(0); + return QTimeZone(*new QUtcTimeZonePrivate()); } /*!