aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/manually/lazytiming.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-15 12:49:18 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-15 19:26:00 +0100
commit9b2ba5e6b3e19a1c9bcdfb2b96e79d426695a9d6 (patch)
treead033062ec877b61851b7028a955b673b3d9e678 /sources/pyside6/tests/manually/lazytiming.py
parent257a7d8512845ca68b8a5568149230469c0eceda (diff)
Add benchmark script for lazy initialization
Pick-to: 6.6 Task-number: PYSIDE-2404 Change-Id: I0e9249504ba1dbcff7317413d9ad8c774e60fdd2 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/tests/manually/lazytiming.py')
-rw-r--r--sources/pyside6/tests/manually/lazytiming.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/sources/pyside6/tests/manually/lazytiming.py b/sources/pyside6/tests/manually/lazytiming.py
new file mode 100644
index 000000000..58a4a628f
--- /dev/null
+++ b/sources/pyside6/tests/manually/lazytiming.py
@@ -0,0 +1,39 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+"""
+Time a repeated Python run
+--------------------------
+
+Usage: python3 lazytiming.py # uses PySide6
+ python3 lazytiming.py <any arg> # uses PyQt6
+ python3 lazytiming.py Qt # uses PyQt6 with QtCore.Qt loaded
+
+It runs the same python for the testing.
+
+Actually comparing PySide6 and PyQt6 in action:
+
+ PYSIDE6_OPTION_LAZY=0 python3 sources/pyside6/tests/manually/lazytiming.py # normal
+ PYSIDE6_OPTION_LAZY=1 python3 sources/pyside6/tests/manually/lazytiming.py # faster
+ python3 sources/pyside6/tests/manually/lazytiming.py xxx # PyQt
+"""
+import subprocess
+import sys
+
+from timeit import default_timer as timer
+
+repeats = 100
+test1 = "PySide6"
+test2 = "PyQt6"
+
+test = test2 if sys.argv[1:] else test1
+cmd = [sys.executable, "-c", f"from {test} import QtCore, QtGui, QtWidgets"]
+
+print(f"{repeats} * {test}")
+
+subprocess.call(cmd) # warmup
+start_time = timer()
+for idx in range(repeats):
+ subprocess.call(cmd)
+stop_time = timer()
+print(f"time per run = {(stop_time - start_time) / repeats}")