mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Add JSON benchmark (#32690)
* Add JSON benchmark * Fix logbook benchmarks * Move logbook import back
This commit is contained in:
parent
44c7743351
commit
d28d1ff657
@ -8,6 +8,7 @@ from timeit import default_timer as timer
|
||||
from typing import Callable, Dict
|
||||
|
||||
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.util import dt as dt_util
|
||||
|
||||
@ -50,8 +51,8 @@ def benchmark(func):
|
||||
|
||||
|
||||
@benchmark
|
||||
async def async_million_events(hass):
|
||||
"""Run a million events."""
|
||||
async def fire_events(hass):
|
||||
"""Fire a million events."""
|
||||
count = 0
|
||||
event_name = "benchmark_event"
|
||||
event = asyncio.Event()
|
||||
@ -78,7 +79,7 @@ async def async_million_events(hass):
|
||||
|
||||
|
||||
@benchmark
|
||||
async def async_million_time_changed_helper(hass):
|
||||
async def time_changed_helper(hass):
|
||||
"""Run a million events through time changed helper."""
|
||||
count = 0
|
||||
event = asyncio.Event()
|
||||
@ -106,7 +107,7 @@ async def async_million_time_changed_helper(hass):
|
||||
|
||||
|
||||
@benchmark
|
||||
async def async_million_state_changed_helper(hass):
|
||||
async def state_changed_helper(hass):
|
||||
"""Run a million events through state changed helper."""
|
||||
count = 0
|
||||
entity_id = "light.kitchen"
|
||||
@ -139,22 +140,19 @@ async def async_million_state_changed_helper(hass):
|
||||
|
||||
|
||||
@benchmark
|
||||
@asyncio.coroutine
|
||||
def logbook_filtering_state(hass):
|
||||
async def logbook_filtering_state(hass):
|
||||
"""Filter state changes."""
|
||||
return _logbook_filtering(hass, 1, 1)
|
||||
return await _logbook_filtering(hass, 1, 1)
|
||||
|
||||
|
||||
@benchmark
|
||||
@asyncio.coroutine
|
||||
def logbook_filtering_attributes(hass):
|
||||
async def logbook_filtering_attributes(hass):
|
||||
"""Filter attribute changes."""
|
||||
return _logbook_filtering(hass, 1, 2)
|
||||
return await _logbook_filtering(hass, 1, 2)
|
||||
|
||||
|
||||
@benchmark
|
||||
@asyncio.coroutine
|
||||
def _logbook_filtering(hass, last_changed, last_updated):
|
||||
async def _logbook_filtering(hass, last_changed, last_updated):
|
||||
from homeassistant.components import logbook
|
||||
|
||||
entity_id = "test.entity"
|
||||
@ -182,7 +180,7 @@ def _logbook_filtering(hass, last_changed, last_updated):
|
||||
|
||||
start = timer()
|
||||
|
||||
list(logbook.humanify(None, yield_events(event)))
|
||||
list(logbook.humanify(hass, yield_events(event)))
|
||||
|
||||
return timer() - start
|
||||
|
||||
@ -194,3 +192,16 @@ async def valid_entity_id(hass):
|
||||
for _ in range(10 ** 6):
|
||||
core.valid_entity_id("light.kitchen")
|
||||
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…
x
Reference in New Issue
Block a user