Skip to content

Commit 9e2950f

Browse files
committed
test: Add blocking ping benchmark
Calls `Ping` D-Bus method on the daemon in sequence.
1 parent 4074f95 commit 9e2950f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
3+
# Copyright (C) 2025 igo95862
4+
5+
# This file is part of python-sdbus
6+
7+
# This library is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 2.1 of the License, or (at your option) any later version.
11+
12+
# This library is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
17+
# You should have received a copy of the GNU Lesser General Public
18+
# License along with this library; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
from __future__ import annotations
21+
22+
from time import perf_counter
23+
24+
import pyperf # type: ignore
25+
from sdbus.unittest import _isolated_dbus
26+
27+
from sdbus import DbusInterfaceCommon
28+
29+
30+
def bench_block_ping(loops: int) -> float:
31+
with _isolated_dbus() as bus:
32+
dbus_interface = DbusInterfaceCommon(
33+
"org.freedesktop.DBus",
34+
"/org/freedesktop/DBus",
35+
bus,
36+
)
37+
38+
start = perf_counter()
39+
40+
for _ in range(loops):
41+
dbus_interface.dbus_ping()
42+
43+
return perf_counter() - start
44+
45+
46+
def main() -> None:
47+
runner = pyperf.Runner()
48+
runner.bench_time_func('sdbus_block_ping', bench_block_ping)
49+
50+
51+
if __name__ == "__main__":
52+
main()

0 commit comments

Comments
 (0)