Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Commit d71de73

Browse files
author
anna-charlotte
committed
fix: benchmark test
Signed-off-by: anna-charlotte <[email protected]>
1 parent 999368d commit d71de73

2 files changed

Lines changed: 33 additions & 182 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from multiprocessing import cpu_count
2+
from time import time
3+
4+
import pytest
5+
6+
from docarray import BaseDocument, DocumentArray
7+
from docarray.utils.apply import apply
8+
9+
10+
class MyDoc(BaseDocument):
11+
title: str
12+
13+
14+
def title_da(doc: MyDoc) -> MyDoc:
15+
return MyDoc(title=doc.title)
16+
17+
18+
@pytest.mark.benchmark
19+
def test_apply_benchmark():
20+
if cpu_count() > 1:
21+
n_docs = 1_000_000
22+
23+
da_1 = DocumentArray[MyDoc]([MyDoc(title=f'{i}') for i in range(n_docs)])
24+
start_time = time()
25+
apply(da=da_1, func=title_da, num_worker=1)
26+
duration_1_cpu = time() - start_time
27+
28+
da_2 = DocumentArray[MyDoc]([MyDoc(title=f'{i}') for i in range(n_docs)])
29+
start_time = time()
30+
apply(da=da_2, func=title_da, num_worker=2)
31+
duration_2_cpu = time() - start_time
32+
33+
assert duration_2_cpu < duration_1_cpu

tests/benchmark_tests/test_multi_processing_apply.py

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)