-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_conversion_int64.py
60 lines (48 loc) · 1.26 KB
/
data_conversion_int64.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
import xnd
import numpy as np
from time import time
# ========================================================================
# Python data conversion
# ========================================================================
#
# Timeit is too slow for large arrays, so this benchmark just uses time.time(),
# which is accurate enough for this purpose.
#
### List of int64_t values ###
lst = [1] * 10000000
# Type inference for reading a medium sized Python list.
print("\nType inference")
print("--------------\n")
start = time()
x = xnd.array(lst)
stop = time()
print(" xnd: ", stop-start)
del x
start = time()
x = np.array(lst)
stop = time()
print(" numpy:", stop-start)
del x
# The same, but with an explicit dtype.
print("\nDtype provided")
print("--------------\n")
start = time()
x = xnd.array(lst, dtype="int64")
stop = time()
print(" xnd: ", stop-start)
del x
start = time()
x = np.array(lst, dtype="int64")
stop = time()
print(" numpy:", stop-start)
del x
# The same, but with a full type that includes the array size. This is
# only possible in xnd.
print("\nFull type provided")
print("-------------------\n")
start = time()
x = xnd.array(lst, type="10000000 * int64")
stop = time()
print(" xnd: ", stop-start)
del x
print("\n")