forked from nschloe/meshio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.py
94 lines (77 loc) · 2.3 KB
/
performance.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import tempfile
import time
import meshio
import meshzoo
def generate_mesh():
"""Generates a fairly large mesh.
"""
points, cells = meshzoo.rectangle(nx=300, ny=300)
return meshio.Mesh(points, {"triangle": cells})
def read_write(plot=False):
mesh = generate_mesh()
formats = [
"abaqus",
"ansys-ascii",
"ansys-binary",
"exodus",
"dolfin-xml",
"gmsh2-ascii",
"gmsh2-binary",
"gmsh4-ascii",
"gmsh4-binary",
"mdpa",
"med",
"medit",
# "moab",
"nastran",
"off",
"permas",
"ply-ascii",
"ply-binary",
"stl-ascii",
"stl-binary",
"vtk-ascii",
"vtk-binary",
"vtu-ascii",
"vtu-binary",
"xdmf",
]
elapsed_write = []
elapsed_read = []
print()
print("format write (s) read(s)")
print()
for fmt in formats:
filename = tempfile.NamedTemporaryFile().name
t = time.time()
meshio.write(filename, mesh, file_format=fmt)
elapsed_write.append(time.time() - t)
t = time.time()
meshio.read(filename, file_format=fmt)
elapsed_read.append(time.time() - t)
print("{0: <12} {1:e} {2:e}".format(fmt, elapsed_write[-1], elapsed_read[-1]))
if plot:
import numpy as np
import matplotlib.pyplot as plt
elapsed_write = np.asarray(elapsed_write)
elapsed_read = np.asarray(elapsed_read)
formats = np.asarray(formats)
fig, ax = plt.subplots(1, 2, figsize=(12, 4))
idx = np.argsort(elapsed_write)
ax[0].bar(range(len(formats)), elapsed_write[idx], align="center")
ax[0].set_xticks(range(len(formats)))
ax[0].set_xticklabels(formats[idx], rotation=90)
ax[0].set_ylabel("time (s)")
ax[0].set_title("write")
ax[0].grid()
idx = np.argsort(elapsed_read)
ax[1].bar(range(len(formats)), elapsed_read[idx], align="center")
ax[1].set_xticks(range(len(formats)))
ax[1].set_xticklabels(formats[idx], rotation=90)
ax[1].set_ylabel("time (s)")
ax[1].set_title("read")
ax[1].grid()
fig.tight_layout()
fig.savefig("performance.png")
if __name__ == "__main__":
read_write(plot=True)