-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_sample_data.py
More file actions
28 lines (24 loc) · 982 Bytes
/
benchmark_sample_data.py
File metadata and controls
28 lines (24 loc) · 982 Bytes
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
import random
import pandas as pd
import numpy as np
NUM_DAYS = 3000 # scaled up to show difference
def original():
df = pd.DataFrame({
"Date": pd.date_range(start="2024-01-01", periods=NUM_DAYS),
"Sales": [random.randint(100, 500) for _ in range(NUM_DAYS)],
"Category": [random.choice(["Electronics", "Clothing", "Home"]) for _ in range(NUM_DAYS)],
"Profit": [random.randint(10, 100) for _ in range(NUM_DAYS)]
})
return df
def optimized():
df = pd.DataFrame({
"Date": pd.date_range(start="2024-01-01", periods=NUM_DAYS),
"Sales": np.random.randint(100, 501, size=NUM_DAYS),
"Category": np.random.choice(["Electronics", "Clothing", "Home"], size=NUM_DAYS),
"Profit": np.random.randint(10, 101, size=NUM_DAYS)
})
return df
if __name__ == "__main__":
import timeit
print("Original:", timeit.timeit(original, number=100))
print("Optimized:", timeit.timeit(optimized, number=100))