Skip to content

Commit

Permalink
Add listing benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman committed Nov 6, 2024
1 parent 6a753c4 commit 509ff26
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions python/tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 509ff26

Please sign in to comment.