forked from hjkornn-phys/algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-performance.py
More file actions
19 lines (14 loc) · 541 Bytes
/
4-performance.py
File metadata and controls
19 lines (14 loc) · 541 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import math
import random
import numpy as np
# 표준편차 계산
def standard_deviation(lst):
m = sum(lst) / len(lst)
variance = sum([(value - m) ** 2 for value in lst])
return math.sqrt(variance / len(lst))
rands = [random.random() for _ in range(0, 1000000)]
numpy_rands = np.array(rands)
# %timeit -n 100 np.std(numpy_rands)
# 3.28 ms ± 214 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
# %timeit -n 100 standard_deviation(rands)
# 131 ms ± 1.03 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)