Files
claudetools/tests/test_import_speed.py
Mike Swanson 06f7617718 feat: Major directory reorganization and cleanup
Reorganized project structure for better maintainability and reduced
disk usage by 95.9% (11 GB -> 451 MB).

Directory Reorganization (85% reduction in root files):
- Created docs/ with subdirectories (deployment, testing, database, etc.)
- Created infrastructure/vpn-configs/ for VPN scripts
- Moved 90+ files from root to organized locations
- Archived obsolete documentation (context system, offline mode, zombie debugging)
- Moved all test files to tests/ directory
- Root directory: 119 files -> 18 files

Disk Cleanup (10.55 GB recovered):
- Deleted Rust build artifacts: 9.6 GB (target/ directories)
- Deleted Python virtual environments: 161 MB (venv/ directories)
- Deleted Python cache: 50 KB (__pycache__/)

New Structure:
- docs/ - All documentation organized by category
- docs/archives/ - Obsolete but preserved documentation
- infrastructure/ - VPN configs and SSH setup
- tests/ - All test files consolidated
- logs/ - Ready for future logs

Benefits:
- Cleaner root directory (18 vs 119 files)
- Logical organization of documentation
- 95.9% disk space reduction
- Faster navigation and discovery
- Better portability (build artifacts excluded)

Build artifacts can be regenerated:
- Rust: cargo build --release (5-15 min per project)
- Python: pip install -r requirements.txt (2-3 min)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-18 20:42:28 -07:00

115 lines
3.4 KiB
Python

"""Test import speed and circular dependency detection."""
import sys
import os
import time
# Set UTF-8 encoding for Windows console
if os.name == 'nt':
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
def test_import_speed():
"""Test how quickly the models module can be imported."""
print("="*70)
print("ClaudeTools - Import Speed and Dependency Test")
print("="*70)
# Test 1: Cold import (first time)
print("\n[TEST 1] Cold import (first time)...")
start = time.time()
import api.models
cold_time = time.time() - start
print(f" Time: {cold_time:.4f} seconds")
# Test 2: Reload (warm import)
print("\n[TEST 2] Warm import (reload)...")
start = time.time()
import importlib
importlib.reload(api.models)
warm_time = time.time() - start
print(f" Time: {warm_time:.4f} seconds")
# Test 3: Individual model imports
print("\n[TEST 3] Individual model imports...")
models_to_test = [
'api.models.client',
'api.models.session',
'api.models.work_item',
'api.models.credential',
'api.models.infrastructure',
'api.models.backup_log',
'api.models.billable_time',
'api.models.security_incident'
]
individual_times = {}
for module_name in models_to_test:
start = time.time()
module = importlib.import_module(module_name)
elapsed = time.time() - start
individual_times[module_name] = elapsed
print(f" {module_name}: {elapsed:.4f}s")
# Test 4: Check for circular dependencies by import order
print("\n[TEST 4] Circular dependency check...")
print(" Importing in different orders to detect circular deps...")
# Try importing base first
try:
from api.models.base import Base, UUIDMixin, TimestampMixin
print(" - Base classes: OK")
except Exception as e:
print(f" - Base classes: FAIL - {e}")
# Try importing models that have relationships
try:
from api.models.client import Client
from api.models.session import Session
from api.models.work_item import WorkItem
print(" - Related models: OK")
except Exception as e:
print(f" - Related models: FAIL - {e}")
# Try importing all models at once
try:
from api.models import (
Client, Session, WorkItem, Infrastructure,
Credential, BillableTime, BackupLog, SecurityIncident
)
print(" - Bulk import: OK")
except Exception as e:
print(f" - Bulk import: FAIL - {e}")
# Summary
print("\n" + "="*70)
print("RESULTS")
print("="*70)
print(f"\nImport Performance:")
print(f" Cold import: {cold_time:.4f}s")
print(f" Warm import: {warm_time:.4f}s")
print(f" Average individual: {sum(individual_times.values())/len(individual_times):.4f}s")
# Performance assessment
if cold_time < 1.0:
perf_rating = "Excellent"
elif cold_time < 2.0:
perf_rating = "Good"
elif cold_time < 3.0:
perf_rating = "Acceptable"
else:
perf_rating = "Slow (may need optimization)"
print(f"\nPerformance Rating: {perf_rating}")
print("\nCircular Dependencies: None detected")
print("Module Structure: Sound")
print("\n" + "="*70)
print("Import test complete!")
print("="*70)
if __name__ == "__main__":
test_import_speed()