-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeTest.py
79 lines (56 loc) · 1.64 KB
/
TimeTest.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import time
def getFactors1(input):
factorIndex = 0
arrOfFactors = [0] * input
for i in range(1,input+1):
x = input%i
if x == 0:
arrOfFactors[factorIndex] = i
factorIndex += 1
for i in (range(len(arrOfFactors)-1,-1,-1)):
if arrOfFactors[i] == 0:
arrOfFactors.pop(i)
return arrOfFactors
def getFactors2(input):
factorIndex = 0
arrOfFactors = [0] * input
for i in range(1,input+1):
x = input%i
if x == 0:
arrOfFactors[factorIndex] = i
factorIndex += 1
for i in (range(len(arrOfFactors)-1,-1,-1)):
if arrOfFactors[i] == 0:
arrOfFactors = arrOfFactors[0:i]
return arrOfFactors
def getFactors3(input):
factorIndex = 0
arrOfFactors = [0] * input
for i in range(1,input+1):
x = input%i
if x == 0:
arrOfFactors[factorIndex] = i
factorIndex += 1
for i in (range(0,len(arrOfFactors))):
if arrOfFactors[i] == 0:
NEWarrOfFactors = arrOfFactors[:i]
break
return NEWarrOfFactors
def getFactors4(input):
arrOfFactors = []
for i in range(1,input+1):
x = input%i
if x == 0:
arrOfFactors.append(i)
return arrOfFactors
def getTime(function, input):
first = time.time()
factor1 = function(input)
second = time.time()
timeTaken = second-first
print(function," took", timeTaken)
factors = 40000
getTime(getFactors1,factors)
getTime(getFactors2,factors)
getTime(getFactors3,factors)
getTime(getFactors4,factors)