mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 01:27:03 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -30,6 +30,7 @@ if not settings.DEBUG:
|
||||
|
||||
def benchmark(name: str, iterations: int = 5):
|
||||
"""Decorator to benchmark a function."""
|
||||
|
||||
def decorator(func: Callable) -> Callable:
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs) -> dict[str, Any]:
|
||||
@@ -48,17 +49,19 @@ def benchmark(name: str, iterations: int = 5):
|
||||
query_counts.append(len(context.captured_queries))
|
||||
|
||||
return {
|
||||
'name': name,
|
||||
'avg_time_ms': statistics.mean(times),
|
||||
'min_time_ms': min(times),
|
||||
'max_time_ms': max(times),
|
||||
'std_dev_ms': statistics.stdev(times) if len(times) > 1 else 0,
|
||||
'avg_queries': statistics.mean(query_counts),
|
||||
'min_queries': min(query_counts),
|
||||
'max_queries': max(query_counts),
|
||||
'iterations': iterations,
|
||||
"name": name,
|
||||
"avg_time_ms": statistics.mean(times),
|
||||
"min_time_ms": min(times),
|
||||
"max_time_ms": max(times),
|
||||
"std_dev_ms": statistics.stdev(times) if len(times) > 1 else 0,
|
||||
"avg_queries": statistics.mean(query_counts),
|
||||
"min_queries": min(query_counts),
|
||||
"max_queries": max(query_counts),
|
||||
"iterations": iterations,
|
||||
}
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -67,7 +70,9 @@ def print_benchmark_result(result: dict[str, Any]) -> None:
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Benchmark: {result['name']}")
|
||||
print(f"{'='*60}")
|
||||
print(f" Time (ms): avg={result['avg_time_ms']:.2f}, min={result['min_time_ms']:.2f}, max={result['max_time_ms']:.2f}")
|
||||
print(
|
||||
f" Time (ms): avg={result['avg_time_ms']:.2f}, min={result['min_time_ms']:.2f}, max={result['max_time_ms']:.2f}"
|
||||
)
|
||||
print(f" Std Dev (ms): {result['std_dev_ms']:.2f}")
|
||||
print(f" Queries: avg={result['avg_queries']:.1f}, min={result['min_queries']}, max={result['max_queries']}")
|
||||
print(f" Iterations: {result['iterations']}")
|
||||
@@ -86,7 +91,7 @@ def run_benchmarks() -> list[dict[str, Any]]:
|
||||
parks = Park.objects.optimized_for_list()[:50]
|
||||
for park in parks:
|
||||
_ = park.operator
|
||||
_ = park.coaster_count_calculated if hasattr(park, 'coaster_count_calculated') else None
|
||||
_ = park.coaster_count_calculated if hasattr(park, "coaster_count_calculated") else None
|
||||
return list(parks)
|
||||
|
||||
results.append(bench_park_list_optimized())
|
||||
@@ -167,22 +172,22 @@ def run_benchmarks() -> list[dict[str, Any]]:
|
||||
|
||||
def print_summary(results: list[dict[str, Any]]) -> None:
|
||||
"""Print a summary table of all benchmarks."""
|
||||
print("\n" + "="*80)
|
||||
print("\n" + "=" * 80)
|
||||
print("BENCHMARK SUMMARY")
|
||||
print("="*80)
|
||||
print("=" * 80)
|
||||
print(f"{'Benchmark':<45} {'Avg Time (ms)':<15} {'Avg Queries':<15}")
|
||||
print("-"*80)
|
||||
print("-" * 80)
|
||||
|
||||
for result in results:
|
||||
print(f"{result['name']:<45} {result['avg_time_ms']:<15.2f} {result['avg_queries']:<15.1f}")
|
||||
|
||||
print("="*80)
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
if True: # Always run when executed
|
||||
print("\n" + "="*80)
|
||||
print("\n" + "=" * 80)
|
||||
print("THRILLWIKI QUERY PERFORMANCE BENCHMARKS")
|
||||
print("="*80)
|
||||
print("=" * 80)
|
||||
print("\nRunning benchmarks...")
|
||||
|
||||
try:
|
||||
@@ -200,4 +205,5 @@ if True: # Always run when executed
|
||||
except Exception as e:
|
||||
print(f"\nError running benchmarks: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user