-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
60 lines (52 loc) · 2 KB
/
config.py
File metadata and controls
60 lines (52 loc) · 2 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
"""
Database configuration for ORM benchmarks.
You can use a local PostgreSQL instance or a free cloud database like:
- Neon (https://neon.tech) - Free tier available
- Supabase (https://supabase.com) - Free tier available
- ElephantSQL (https://elephantsql.com) - Free tier available
For accurate benchmarks, a local database is recommended to eliminate network latency.
"""
import os
# Database configuration - set these environment variables or modify directly
DATABASE_CONFIG = {
"host": os.getenv("DB_HOST", "localhost"),
"port": int(os.getenv("DB_PORT", "5432")),
"user": os.getenv("DB_USER", "postgres"),
"password": os.getenv("DB_PASSWORD", "postgres"),
"database": os.getenv("DB_NAME", "orm_benchmark"),
}
# Connection URLs
def get_database_url() -> str:
"""Get PostgreSQL connection URL for SQLAlchemy."""
return (
f"postgresql+asyncpg://{DATABASE_CONFIG['user']}:{DATABASE_CONFIG['password']}"
f"@{DATABASE_CONFIG['host']}:{DATABASE_CONFIG['port']}/{DATABASE_CONFIG['database']}"
)
def get_tortoise_config() -> dict:
"""Get Tortoise ORM configuration."""
return {
"connections": {
"default": {
"engine": "tortoise.backends.asyncpg",
"credentials": {
"host": DATABASE_CONFIG["host"],
"port": DATABASE_CONFIG["port"],
"user": DATABASE_CONFIG["user"],
"password": DATABASE_CONFIG["password"],
"database": DATABASE_CONFIG["database"],
},
}
},
"apps": {
"models": {
"models": ["models.tortoise_models"],
"default_connection": "default",
}
},
}
# Benchmark settings
BENCHMARK_SETTINGS = {
"num_records": 1000, # Number of records to create for bulk operations
"num_iterations": 100, # Number of iterations for each benchmark
"warmup_iterations": 10, # Warmup iterations before actual benchmarking
}