-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
66 lines (45 loc) · 1.77 KB
/
benchmark.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
from fastlist import FastList
import random; random.seed(42)
from time import time
print("*** 10 ints ***")
L = [random.randrange(int(10)) for _ in range(int(10))]
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 10 strings ***")
L = list(map(str, L))
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 1e3 ints ***")
L = [random.randrange(int(1e3)) for _ in range(int(1e3))]
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 1e3 strings ***")
L = list(map(str, L))
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 1e7 ints ***")
L = [random.randrange(int(1e7)) for _ in range(int(1e7))]
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 1e7 strings ***")
L = list(map(str, L))
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)
print("*** 1e7 ints + 1 float (to disable the optimization while keeping the precheck)***")
L = [random.randrange(int(1e7)) for _ in range(int(1e7))] + [4.2]
F = FastList(L[:])
start = time(); F.fastsort(); print("F.fastsort():", time()-start)
F = FastList(L[:])
start = time(); F.sort(); print("F.sort():", time()-start)