-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTimeComparison.py
More file actions
41 lines (35 loc) · 1.06 KB
/
TimeComparison.py
File metadata and controls
41 lines (35 loc) · 1.06 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
import numpy as np
from SumArray import SumArray
from SumArrayParallel import SumArrayParallel
Array1 = np.random.rand(int(1e8))
Length1 = len(Array1)
import time
def time_usage(func):
def wrapper(*args, **kwargs):
beg_ts = time.time()
retval = func(*args, **kwargs)
end_ts = time.time()
print("elapsed time: %f" % (end_ts - beg_ts))
return retval
return wrapper
@time_usage
def SumSpeedTest(Method, Array, Length):
if Method == "python":
return sum(Array)
if Method == "numpy":
return np.sum(Array)
if Method == "c++":
return SumArray.C_SumArray(Array, Length)
if Method == "c++OpenMP":
return SumArrayParallel.C_SumArray(Array, Length)
Result = SumSpeedTest("python", Array1, Length1)
print(Result)
Result2 = SumSpeedTest("numpy", Array1, Length1)
print(Result2)
Result3 = SumSpeedTest("c++", Array1, Length1)
print(Result3)
Result4 = SumSpeedTest("c++OpenMP", Array1, Length1)
print(Result4)
#%timeit sum(Array1)
#%timeit np.sum(Array1)
#%timeit SumArray.C_SumArray(Array1, Length1)