Add JSON benchmark (#32690)
* Add JSON benchmark * Fix logbook benchmarks * Move logbook import back
This commit is contained in:
parent
44c7743351
commit
d28d1ff657
1 changed files with 24 additions and 13 deletions
|
@ -8,6 +8,7 @@ from timeit import default_timer as timer
|
||||||
from typing import Callable, Dict
|
from typing import Callable, Dict
|
||||||
|
|
||||||
from homeassistant import core
|
from homeassistant import core
|
||||||
|
from homeassistant.components.websocket_api.const import JSON_DUMP
|
||||||
from homeassistant.const import ATTR_NOW, EVENT_STATE_CHANGED, EVENT_TIME_CHANGED
|
from homeassistant.const import ATTR_NOW, EVENT_STATE_CHANGED, EVENT_TIME_CHANGED
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
@ -50,8 +51,8 @@ def benchmark(func):
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
async def async_million_events(hass):
|
async def fire_events(hass):
|
||||||
"""Run a million events."""
|
"""Fire a million events."""
|
||||||
count = 0
|
count = 0
|
||||||
event_name = "benchmark_event"
|
event_name = "benchmark_event"
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
@ -78,7 +79,7 @@ async def async_million_events(hass):
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
async def async_million_time_changed_helper(hass):
|
async def time_changed_helper(hass):
|
||||||
"""Run a million events through time changed helper."""
|
"""Run a million events through time changed helper."""
|
||||||
count = 0
|
count = 0
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
@ -106,7 +107,7 @@ async def async_million_time_changed_helper(hass):
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
async def async_million_state_changed_helper(hass):
|
async def state_changed_helper(hass):
|
||||||
"""Run a million events through state changed helper."""
|
"""Run a million events through state changed helper."""
|
||||||
count = 0
|
count = 0
|
||||||
entity_id = "light.kitchen"
|
entity_id = "light.kitchen"
|
||||||
|
@ -139,22 +140,19 @@ async def async_million_state_changed_helper(hass):
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
@asyncio.coroutine
|
async def logbook_filtering_state(hass):
|
||||||
def logbook_filtering_state(hass):
|
|
||||||
"""Filter state changes."""
|
"""Filter state changes."""
|
||||||
return _logbook_filtering(hass, 1, 1)
|
return await _logbook_filtering(hass, 1, 1)
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
@asyncio.coroutine
|
async def logbook_filtering_attributes(hass):
|
||||||
def logbook_filtering_attributes(hass):
|
|
||||||
"""Filter attribute changes."""
|
"""Filter attribute changes."""
|
||||||
return _logbook_filtering(hass, 1, 2)
|
return await _logbook_filtering(hass, 1, 2)
|
||||||
|
|
||||||
|
|
||||||
@benchmark
|
@benchmark
|
||||||
@asyncio.coroutine
|
async def _logbook_filtering(hass, last_changed, last_updated):
|
||||||
def _logbook_filtering(hass, last_changed, last_updated):
|
|
||||||
from homeassistant.components import logbook
|
from homeassistant.components import logbook
|
||||||
|
|
||||||
entity_id = "test.entity"
|
entity_id = "test.entity"
|
||||||
|
@ -182,7 +180,7 @@ def _logbook_filtering(hass, last_changed, last_updated):
|
||||||
|
|
||||||
start = timer()
|
start = timer()
|
||||||
|
|
||||||
list(logbook.humanify(None, yield_events(event)))
|
list(logbook.humanify(hass, yield_events(event)))
|
||||||
|
|
||||||
return timer() - start
|
return timer() - start
|
||||||
|
|
||||||
|
@ -194,3 +192,16 @@ async def valid_entity_id(hass):
|
||||||
for _ in range(10 ** 6):
|
for _ in range(10 ** 6):
|
||||||
core.valid_entity_id("light.kitchen")
|
core.valid_entity_id("light.kitchen")
|
||||||
return timer() - start
|
return timer() - start
|
||||||
|
|
||||||
|
|
||||||
|
@benchmark
|
||||||
|
async def json_serialize_states(hass):
|
||||||
|
"""Serialize million states with websocket default encoder."""
|
||||||
|
states = [
|
||||||
|
core.State("light.kitchen", "on", {"friendly_name": "Kitchen Lights"})
|
||||||
|
for _ in range(10 ** 6)
|
||||||
|
]
|
||||||
|
|
||||||
|
start = timer()
|
||||||
|
JSON_DUMP(states)
|
||||||
|
return timer() - start
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue