File: chunkshape-testing.py

package info (click to toggle)
pytables 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,272 kB
  • sloc: ansic: 82,216; python: 65,569; cpp: 753; sh: 394; makefile: 106
file content (134 lines) | stat: -rw-r--r-- 3,133 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3

"""Simple benchmark for testing chunkshapes and nrowsinbuf."""

from time import perf_counter as clock

import numpy as np

import tables as tb

L = 20
N = 2000
M = 30
complevel = 1

recarray = np.empty(shape=2, dtype="(2,2,2)i4,(2,3,3)f8,i4,i8")

f = tb.open_file("chunkshape.h5", mode="w")

# t = f.create_table(f.root, 'table', recarray, "mdim recarray")

# a0 = f.create_array(f.root, 'field0', recarray['f0'], "mdim int32 array")
# a1 = f.create_array(f.root, 'field1', recarray['f1'], "mdim float64 array")

# c0 = f.create_carray(f.root, 'cfield0',
#                     tables.Int32Atom(), (2,2,2),
#                     "mdim int32 carray")
# c1 = f.create_carray(f.root, 'cfield1',
#                     tables.Float64Atom(), (2,3,3),
#                     "mdim float64 carray")

f1 = tb.open_file("chunkshape1.h5", mode="w")
c1 = f.create_carray(
    f1.root,
    "cfield1",
    tb.Int32Atom(),
    (L, N, M),
    "scalar int32 carray",
    tb.Filters(complevel=0),
)

t1 = clock()
c1[:] = np.empty(shape=(L, 1, 1), dtype="int32")
print("carray1 populate time:", clock() - t1)
f1.close()


f2 = tb.open_file("chunkshape2.h5", mode="w")
c2 = f.create_carray(
    f2.root,
    "cfield2",
    tb.Int32Atom(),
    (L, M, N),
    "scalar int32 carray",
    tb.Filters(complevel),
)

t1 = clock()
c2[:] = np.empty(shape=(L, 1, 1), dtype="int32")
print("carray2 populate time:", clock() - t1)
f2.close()

f0 = tb.open_file("chunkshape0.h5", mode="w")
e0 = f.create_earray(
    f0.root,
    "efield0",
    tb.Int32Atom(),
    (0, L, M),
    "scalar int32 carray",
    tb.Filters(complevel),
    expectedrows=N,
)

t1 = clock()
e0.append(np.empty(shape=(N, L, M), dtype="int32"))
print("earray0 populate time:", clock() - t1)
f0.close()

f1 = tb.open_file("chunkshape1.h5", mode="w")
e1 = f.create_earray(
    f1.root,
    "efield1",
    tb.Int32Atom(),
    (L, 0, M),
    "scalar int32 carray",
    tb.Filters(complevel),
    expectedrows=N,
)

t1 = clock()
e1.append(np.empty(shape=(L, N, M), dtype="int32"))
print("earray1 populate time:", clock() - t1)
f1.close()


f2 = tb.open_file("chunkshape2.h5", mode="w")
e2 = f.create_earray(
    f2.root,
    "efield2",
    tb.Int32Atom(),
    (L, M, 0),
    "scalar int32 carray",
    tb.Filters(complevel),
    expectedrows=N,
)

t1 = clock()
e2.append(np.empty(shape=(L, M, N), dtype="int32"))
print("earray2 populate time:", clock() - t1)
f2.close()

# t1=time()
# c2[:] = np.empty(shape=(M, N), dtype="int32")
# print "carray populate time:", time()-t1

# f3 = f.create_carray(f.root, 'cfield3',
#                     tables.Float64Atom(), (3,),
#                     "scalar float64 carray", chunkshape=(32,))

# e2 = f.create_earray(f.root, 'efield2',
#                     tables.Int32Atom(), (0, M),
#                     "scalar int32 carray", expectedrows=N)
# t1=time()
# e2.append(np.empty(shape=(N, M), dtype="int32"))
# print "earray populate time:", time()-t1

# t1=time()
# c2._f_copy(newname='cfield2bis')
# print "carray copy time:", time()-t1
# t1=time()
# e2._f_copy(newname='efield2bis')
# print "earray copy time:", time()-t1

f.close()