-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Airspeed velocity benchmarks #1
base: master
Are you sure you want to change the base?
Conversation
Thanks, this takes a bit of time to comprehend. I have a couple of remarks:
|
It is pretty thick code, I agree.
Done.
I'm pretty sure it's because the Python object has to be constructed each time you do something like
There is I would just use |
b0b95ce
to
c0cd204
Compare
I'd like to go to the bottom of the issue of different results for tuple element access. I don't think it's a loop issue, because all access benchmarks have the same loop. One reason might be that Are you sure that single elements and not subtrees are accessed (I don't have time to really dig into the code)? |
Oh. If |
Actually, in the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To expand on the previous issue.
self.array = globals()[module].array(lst) | ||
|
||
def time_access_tuple(self, size, dim, module): | ||
self.array[(0,) * dim[1]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the access for tuple
access. Equivalent to a[0, 0, ...]
where the ellipsis is a continuation and not a Python ellipsis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NumPy does not appear to be able to use multi-indexing on tuples:
>>> import numpy as np
>>> lst = [('Rex', 9, 81.0)] * 100
>>> dt = np.dtype([('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])
>>> x = np.array(lst, dtype=dt)
>>> y = x[0][0]
>>> type(y)
<class 'numpy.str_'>
>>>
>>> y = x[0, 0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: too many indices for array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't test tuples
in the element access at all, I could add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fast benchmark measures y = x[0][0]
, i.e. it accesses the 'Rex'
tuple element, not the array element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xnd
is able to access through tuples:
>>> lst = [('Rex', 9, 81.0)] * 100
>>> x = xnd(lst)
>>> x[0, 0]
xnd('Rex', type='string')
So that should be even faster for xnd
.
self.array[(0,) * dim[1]] | ||
|
||
def time_access_chained(self, size, dim, module): | ||
a = self.array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I cache a
, then in a loop, access it. This is equivalent to a[0][0]...
In general I think people are likely to write benchmarks for small arrays. Here is the construction benchmark when using the from xnd import Xnd
...
for i in range(repeat):
x = Xnd(ndt("1 * int64"), lst)
...
|
So I'll rewrite the class in C now before publishing the benchmarks. |
No description provided.