From 509ff2663abf752d8212f0cb7918035d798ce17f Mon Sep 17 00:00:00 2001 From: Adam Binford Date: Wed, 6 Nov 2024 12:49:46 -0500 Subject: [PATCH] Add listing benchmark --- python/tests/test_benchmark.py | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/python/tests/test_benchmark.py b/python/tests/test_benchmark.py index 7cc7d6f..94ce548 100644 --- a/python/tests/test_benchmark.py +++ b/python/tests/test_benchmark.py @@ -6,20 +6,31 @@ from hdfs_native import Client -def do_work(client: Client): - def func(path: str): - client.create(path).close() - return client.delete(path) +@pytest.mark.benchmark +def test_benchmark_threading(client: Client, benchmark: BenchmarkFixture): + def do_work(): + def func(path: str): + client.create(path).close() + return client.delete(path) + + with ThreadPoolExecutor(100) as executor: + futures = [] + for i in range(1000): + futures.append(executor.submit(func, f"/bench{i}")) - with ThreadPoolExecutor(100) as executor: - futures = [] - for i in range(1000): - futures.append(executor.submit(func, f"/bench{i}")) + for future in as_completed(futures): + assert future.result() - for future in as_completed(futures): - assert future.result() + benchmark(do_work) @pytest.mark.benchmark -def test_threading(client: Client, benchmark: BenchmarkFixture): - benchmark(do_work, client) +def test_benchmark_listing(client: Client, benchmark: BenchmarkFixture): + for i in range(1000): + client.create(f"/bench{i}").close() + + def do_work(): + for _ in client.list_status("/"): + pass + + benchmark(do_work)