I test ujson.loads, then found it takes about 2-3ms in my cases. Here are my tests. It seems to be load time depending on input length rather than nested dictionary. Could it be improved under 1ms?
Code: Select all
def test_json(d):
t0 = time.ticks_us()
ret = json.loads(d)
t1 = time.ticks_us()
print('dt = %sms' % ((t1-t0)/1000,))
return ret
>>>
>>> d
'{"a": 2990, "b": {"c": 2, "c2": [[10,100], 1]}, "d": ["OFF", {"foo": "ON", "foo2": "OFF"}]}'
>>> test_json(d)
dt = 2.593ms
{'a': 2990, 'd': ['OFF', {'foo2': 'OFF', 'foo': 'ON'}], 'b': {'c': 2, 'c2': [[10, 100], 1]}}
>>>
>>> d2
'{"battery":93,"battery_low":false,"contact":false,"linkquality":127,"tamper":false,"voltage":2900}'
>>> test_json(d2)
dt = 2.769ms
{'linkquality': 127, 'contact': False, 'battery': 93, 'battery_low': False, 'tamper': False, 'voltage': 2900}
>>>