ha-core/homeassistant/util
Paul Ganssle efa5c59559
Replace hand-rolled binary search with bisect_left (#50410)
The `bisect` module exposes a `bisect_left` function which does
basically what the bulk of `_lower_bound` does. From my tests, it is
slightly faster (~5%) in the probably common ideal case where `arr` is short.
In the worst case scenario, `bisect.bisect_left` is *much* faster.

```
>>> arr = list(range(60))
>>> cmp = 59
>>> %timeit _lower_bound(arr, cmp)
736 ns ± 6.24 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> %timeit bisect_lower_bound(arr, cmp)
290 ns ± 7.77 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
```

I doubt this is a huge bottleneck or anything, but I think it's a bit
more readable, and it's more efficient, so it seems like it's mostly a
win.

This commit *will* add a new unconditional import for `bisect` when
importing `util.dt`, and `bisect` is not currently imported for any of
the standard library modules. It is possible to make this conditional by
placing `import bisect` in the _lower_bound function, or in the function
it's nested in.
2021-05-11 08:18:20 -07:00
..
yaml Update pylint to 2.8.0 (#49637) 2021-04-24 14:39:24 -10:00
__init__.py Update typing syntax (#49480) 2021-04-20 17:40:41 +02:00
aiohttp.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
async_.py Update typing syntax (#49480) 2021-04-20 17:40:41 +02:00
color.py Improve color conversion for RGBWW lights (#49807) 2021-04-28 15:46:41 +02:00
decorator.py Lint exclusions (#28655) 2019-11-16 10:22:07 +01:00
distance.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
dt.py Replace hand-rolled binary search with bisect_left (#50410) 2021-05-11 08:18:20 -07:00
executor.py Ensure shutdown does not deadlock (#49282) 2021-04-18 08:55:51 -10:00
json.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
location.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
logging.py Update typing syntax (#49480) 2021-04-20 17:40:41 +02:00
network.py Add support for capturing renewals to dhcp discovery (#48242) 2021-03-30 15:41:12 +02:00
package.py Update pylint to 2.8.0 (#49637) 2021-04-24 14:39:24 -10:00
percentage.py Remove redundant text from documentation (#49262) 2021-04-15 18:05:07 +02:00
pil.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
pressure.py Cleanup unused loggers (components N-Z + tests) (#41982) 2020-10-16 21:24:08 -05:00
process.py Remove some unneeded pylint disables, update ref to util.process one (#49314) 2021-04-17 09:25:20 +02:00
ruamel_yaml.py Don't ignore mypy errors by default (#49270) 2021-04-26 14:23:21 +02:00
ssl.py Lint suppression cleanups (#47248) 2021-03-02 09:02:04 +01:00
temperature.py Sort imports according to PEP8 for 'homeassistant' folder (#29789) 2019-12-09 16:42:10 +01:00
thread.py Ensure shutdown does not deadlock (#49282) 2021-04-18 08:55:51 -10:00
timeout.py Rewrite of not a == b occurances (#48132) 2021-03-20 01:27:04 +01:00
unit_system.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
uuid.py Improve performance of generating non-cryptographically secure uuids (#41314) 2020-10-07 16:37:01 +02:00
volume.py Cleanup unused loggers (components N-Z + tests) (#41982) 2020-10-16 21:24:08 -05:00