home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 902482335

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/pull/5667#issuecomment-902482335 https://api.github.com/repos/pydata/xarray/issues/5667 902482335 IC_kwDOAMm_X841ysmf 14371165 2021-08-20T07:06:19Z 2021-08-20T07:10:16Z MEMBER

Here's further tests to check how fast different class checkers are:

```python from typing import MutableMapping

class Test2(MutableMapping): def init(self, args, kwargs): self.data = dict(args, **kwargs)

def __getitem__(self, key):
    pass

def __setitem__(self, key, value):
    pass

def __delitem__(self, key):
    pass

def __iter__(self):
    pass

def __len__(self):
    pass

b = Test2()

%timeit issubclass(type(b), MutableMapping) 711 ns ± 5.33 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit isinstance(b, MutableMapping) 853 ns ± 6.29 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

If you want to get really fast you can check for one of the required attributes MutableMapping has

%timeit hasattr(b, "update") 82.6 ns ± 0.181 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) ```

isinstance is rather slow as can be seen. Considering just doing dict(b) takes about 200ns which is basically what the original implementation was it doesn't feel that good to add a check that adds 800ns of wait time.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  958878760
Powered by Datasette · Queries took 0.92ms · About: xarray-datasette