-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_performance.py
More file actions
93 lines (72 loc) · 3.71 KB
/
test_performance.py
File metadata and controls
93 lines (72 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""Test script to measure performance improvements with SQLite database."""
import time
from pathlib import Path
from core.data_loader import TranscriptLoader
from core.database import TranscriptDatabase
def test_loading_performance():
"""Compare loading performance with and without database."""
print("🔍 Testing Transcript Loading Performance\n")
print("=" * 60)
# Test 1: Initial load without database (baseline)
print("\n📊 Test 1: Loading WITHOUT database (baseline)")
loader_no_db = TranscriptLoader(use_database=False)
loader_no_db.discover_transcript_files()
print(f"Found {len(loader_no_db.file_paths)} transcript files")
start = time.time()
messages, conversations = loader_no_db.load_all_files(show_progress=True)
no_db_time = time.time() - start
print(f"✅ Loaded {len(messages)} messages in {no_db_time:.2f} seconds")
print(f" Speed: {len(messages) / no_db_time:.0f} messages/second")
# Test 2: Initial load WITH database (first time - building cache)
print("\n📊 Test 2: Initial load WITH database (building cache)")
# Clear database first
db = TranscriptDatabase()
db.clear_database()
loader_with_db = TranscriptLoader(use_database=True)
loader_with_db.discover_transcript_files()
start = time.time()
messages, conversations = loader_with_db.load_all_files(show_progress=True)
initial_db_time = time.time() - start
print(f"✅ Loaded {len(messages)} messages in {initial_db_time:.2f} seconds")
print(f" Speed: {len(messages) / initial_db_time:.0f} messages/second")
# Test 3: Subsequent load WITH database (using cache)
print("\n📊 Test 3: Subsequent load WITH database (using cache)")
loader_cached = TranscriptLoader(use_database=True)
loader_cached.discover_transcript_files()
start = time.time()
messages, conversations = loader_cached.load_all_files(show_progress=True)
cached_db_time = time.time() - start
print(f"✅ Loaded {len(messages)} messages in {cached_db_time:.2f} seconds")
print(f" Speed: {len(messages) / cached_db_time:.0f} messages/second")
# Get database statistics
stats = loader_cached.get_statistics()
# Print summary
print("\n" + "=" * 60)
print("📈 PERFORMANCE SUMMARY")
print("=" * 60)
print(f"\n1. Without Database: {no_db_time:.2f} seconds")
print(f"2. With Database (first): {initial_db_time:.2f} seconds")
print(f"3. With Database (cached): {cached_db_time:.2f} seconds")
if cached_db_time > 0:
speedup = no_db_time / cached_db_time
print(f"\n🚀 SPEEDUP: {speedup:.1f}x faster with cached database!")
print(f"\n📊 Database Statistics:")
print(f" - Database size: {stats.get('database_size_mb', 0):.2f} MB")
print(f" - Total messages: {stats.get('total_messages', 0):,}")
print(f" - Total sessions: {stats.get('total_conversations', 0)}")
print(f" - Unique tools: {len(stats.get('unique_tools', []))}")
# Test 4: Incremental update (modify one file)
print("\n📊 Test 4: Incremental update (simulating file change)")
# Touch a file to simulate modification
if loader_cached.file_paths:
test_file = loader_cached.file_paths[0]
print(f" Simulating change to: {test_file.name}")
test_file.touch()
start = time.time()
messages, conversations = loader_cached.load_all_files(show_progress=True)
incremental_time = time.time() - start
print(f"✅ Incremental update took {incremental_time:.2f} seconds")
print(f" Only reloaded modified files!")
if __name__ == "__main__":
test_loading_performance()