core/homeassistant
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
..
auth Rename FlowResultDict to FlowResult (#49847) 2021-04-29 13:40:51 +02:00
components Improve type annotations for GIOS integration (#50454) 2021-05-11 07:57:24 -07:00
generated Add dhcp support to guardian (#50378) 2021-05-10 21:26:15 -05:00
helpers Fix event action return value typing (#50353) 2021-05-11 16:23:59 +02:00
scripts
util Replace hand-rolled binary search with bisect_left (#50410) 2021-05-11 08:18:20 -07:00
__init__.py
__main__.py Update pylint to 2.8.0 (#49637) 2021-04-24 14:39:24 -10:00
block_async_io.py
bootstrap.py
config.py Don't overwrite existing files when generating configuration (#49815) 2021-04-28 17:15:04 +02:00
config_entries.py Allow passing options in config flow entry creation (#49912) 2021-05-05 22:14:01 -07:00
const.py Add missing type hints in http component (#50411) 2021-05-10 14:30:47 -07:00
core.py Migrate from pytz to python-dateutil (#49643) 2021-05-07 22:46:26 -07:00
data_entry_flow.py Allow passing options in config flow entry creation (#49912) 2021-05-05 22:14:01 -07:00
exceptions.py
loader.py Change log severity from warn to error for custom integration version (#49726) 2021-04-26 15:04:39 -07:00
package_constraints.txt Use zoneinfo instead of dateutil (#50387) 2021-05-10 08:32:29 -07:00
requirements.py Update pylint to 2.8.0 (#49637) 2021-04-24 14:39:24 -10:00
runner.py
setup.py
strings.json