Created
March 17, 2018 11:05
-
-
Save lijunzh/6bd98dbec3e646c14dd31cb337a4ef11 to your computer and use it in GitHub Desktop.
Read and writing performance test between numpy.ndarray (.npy) vs obspy.Stream (.mseed).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.6.4 |Anaconda custom (64-bit)| (default, Mar 12 2018, 20:05:31) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: import numpy as np | |
In [2]: import obspy | |
In [3]: data = np.random.randn(6000, 3, 2000) | |
In [4]: traces = [] | |
...: for i, frame in enumerate(data): | |
...: for j, trace in enumerate(frame): | |
...: traces.append(obspy.Trace(data=trace)) | |
...: st = obspy.Stream(traces) | |
...: | |
In [5]: %timeit np.save("data.npy", data) | |
398 ms ± 3.96 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) | |
In [6]: %timeit data = np.load("data.npy") | |
188 ms ± 868 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) | |
In [7]: %timeit st.write("data.mseed") | |
2.24 s ± 48.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) | |
In [8]: %timeit st = obspy.read("data.mseed") | |
3.09 s ± 78.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment