Skip to content

Commit 1eefaf6

Browse files
committed
fix: added benchmark_test.py script
1 parent b2312e1 commit 1eefaf6

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

benchmark_test.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import logging
2+
import shutil
3+
import time
4+
from pathlib import Path
5+
from gptme_rag.benchmark import RagBenchmark
6+
7+
# Configure logging to show only ERROR level
8+
logging.getLogger('chromadb').setLevel(logging.ERROR)
9+
logging.getLogger('gptme_rag').setLevel(logging.ERROR)
10+
11+
# Create and clean test directories
12+
test_dir = Path("benchmark_data")
13+
index_dir = Path("benchmark_index")
14+
15+
# Clean up any existing test data
16+
if test_dir.exists():
17+
shutil.rmtree(test_dir)
18+
if index_dir.exists():
19+
shutil.rmtree(index_dir)
20+
21+
test_dir.mkdir(exist_ok=True)
22+
23+
# Create test documents in a subdirectory
24+
docs_dir = test_dir / "docs"
25+
docs_dir.mkdir(exist_ok=True)
26+
27+
# Create some test documents
28+
for i in range(10):
29+
content = f"""# Document {i}
30+
31+
This is test document {i} with some content about Python, documentation, and examples.
32+
33+
## Section 1
34+
35+
Detailed content about programming concepts.
36+
37+
## Section 2
38+
39+
More technical details and implementation examples.
40+
41+
## Section 3
42+
43+
Additional information and use cases.
44+
"""
45+
(docs_dir / f"doc{i}.md").write_text(content)
46+
47+
# Create a separate file for watch testing
48+
watch_test_file = docs_dir / "watch_test.md"
49+
watch_test_file.write_text("Initial content for watch testing")
50+
51+
try:
52+
# Initialize benchmark suite
53+
benchmark = RagBenchmark(index_dir=index_dir)
54+
55+
# Run indexing benchmark
56+
print("\nRunning indexing benchmark...")
57+
index_result = benchmark.run_indexing_benchmark(
58+
docs_dir,
59+
pattern="*.md"
60+
)
61+
62+
# Run search benchmark with various queries
63+
print("\nRunning search benchmark...")
64+
search_result = benchmark.run_search_benchmark(
65+
queries=[
66+
"python programming",
67+
"documentation examples",
68+
"technical details",
69+
"implementation guide",
70+
],
71+
n_results=5
72+
)
73+
74+
# Custom file watching benchmark
75+
print("\nRunning file watch benchmark...")
76+
def watch_operation():
77+
updates = 0
78+
start_time = time.time()
79+
duration = 5.0
80+
update_interval = 1.0 # 1 second between updates
81+
82+
while time.time() - start_time < duration:
83+
# Write meaningful content that changes each time
84+
content = f"""# Watch Test Update {updates}
85+
86+
This is update number {updates} for the watch test.
87+
Time: {time.time()}
88+
89+
## Content
90+
- Update sequence: {updates}
91+
- Timestamp: {time.time()}
92+
- Test data: Example content for indexing
93+
"""
94+
watch_test_file.write_text(content)
95+
updates += 1
96+
time.sleep(update_interval)
97+
98+
return {
99+
"items_processed": updates,
100+
"metrics": {
101+
"total_updates": updates,
102+
"updates_per_second": updates / duration,
103+
}
104+
}
105+
106+
watch_result = benchmark.measure_operation(
107+
watch_operation,
108+
"file_watching"
109+
)
110+
111+
# Print results
112+
print("\nBenchmark Results:")
113+
benchmark.print_results()
114+
115+
finally:
116+
# Clean up test data
117+
if test_dir.exists():
118+
shutil.rmtree(test_dir)
119+
if index_dir.exists():
120+
shutil.rmtree(index_dir)

0 commit comments

Comments
 (0)