forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench_records.py
40 lines (30 loc) · 1.36 KB
/
bench_records.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
from .common import Benchmark
import numpy as np
class Records(Benchmark):
def setup(self):
self.l50 = np.arange(1000)
self.fields_number = 10000
self.arrays = [self.l50 for _ in range(self.fields_number)]
self.formats = [self.l50.dtype.str for _ in range(self.fields_number)]
self.formats_str = ','.join(self.formats)
self.dtype_ = np.dtype(
[
('field_{}'.format(i), self.l50.dtype.str)
for i in range(self.fields_number)
]
)
self.buffer = self.l50.tostring() * self.fields_number
def time_fromarrays_w_dtype(self):
np.core.records.fromarrays(self.arrays, dtype=self.dtype_)
def time_fromarrays_wo_dtype(self):
np.core.records.fromarrays(self.arrays)
def time_fromarrays_formats_as_list(self):
np.core.records.fromarrays(self.arrays, formats=self.formats)
def time_fromarrays_formats_as_string(self):
np.core.records.fromarrays(self.arrays, formats=self.formats_str)
def time_fromstring_w_dtype(self):
np.core.records.fromstring(self.buffer, dtype=self.dtype_)
def time_fromstring_formats_as_list(self):
np.core.records.fromstring(self.buffer, formats=self.formats)
def time_fromstring_formats_as_string(self):
np.core.records.fromstring(self.buffer, formats=self.formats_str)