-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
31 lines (25 loc) · 915 Bytes
/
run.py
File metadata and controls
31 lines (25 loc) · 915 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
29
30
31
import numpy as np
import time
def numpy_benchmark():
results = {}
# Matrix multiplication (BLAS-backed, uses multi-threading internally)
A = np.random.rand(1000, 1000)
B = np.random.rand(1000, 1000)
start = time.time()
C = np.dot(A, B)
results["Matrix Multiplication (1000x1000)"] = round(time.time() - start, 2)
# Element-wise math (vectorized ops)
x = np.random.rand(10_000_000)
start = time.time()
y = np.sin(x) + np.log(x + 1)
results["Element-wise Computation (10M)"] = round(time.time() - start, 2)
# Summation (uses reduction across array)
start = time.time()
total = np.sum(x)
results["Sum Reduction (10M)"] = round(time.time() - start, 2)
return results
if __name__ == "__main__":
results = numpy_benchmark()
print("\n🧪 NumPy Benchmark Results")
for task, t in results.items():
print(f"{task}: {t} seconds")