From 22e66638a6c984d366057d1bb0c6de6dc65df373 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Sat, 22 Feb 2025 15:41:17 +0100 Subject: [PATCH] Optimize QTimeZone::utc() Instead of using the QTimeZone ctor taking a string representing UTC which then first needs to be parsed, use the offset-from-UTC ctor with an offset of 0. This approach is much faster, compare the following results for the tst_QTimeZone::utc benchmark as built on my 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: 358.686871 nsecs per iteration (total: 358,686,513, iterations: 999999) 896.524312 CPU cycles per iteration, 2,5 GHz (total: 896,523,416, iterations: 999999) 2,227.000427 instructions per iteration, 2,484 instr/cycle (total: 2,226,998,200, iterations: 999999) 560.000375 branch instructions per iteration, 1,56 G/sec (total: 559,999,815, iterations: 999999) After: 102.004937 nsecs per iteration (total: 102,004,835, iterations: 999999) 452.836869 CPU cycles per iteration, 4,44 GHz (total: 452,836,417, iterations: 999999) 1,182.801068 instructions per iteration, 2,612 instr/cycle (total: 1,182,799,886, iterations: 999999) 267.143901 branch instructions per iteration, 2,62 G/sec (total: 267,143,634, iterations: 999999) Relative Delta: before after improvement nsecs 358.7 102.0 3.52x cycles 896.5 452.8 1.98x instr. 2227.0 1182.8 1.88x branch 560.0 267.1 2.10x This is quite a significant change for such a trivial patch. Pick-to: 6.8 Change-Id: I5872fe8f1158ff9f6bf306ca8b069559cb59beec Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz (cherry picked from commit 765193693982abdbc53910ff0d7d1149332ca83e) Reviewed-by: Qt Cherry-pick Bot --- 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 906a42fc7bb..a23b1e4c9e7 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(QTimeZonePrivate::utcQByteArray()); + return QTimeZone(0); } /*!