more accurate benchmarking by adding _to_dict helper
This commit is contained in:
parent
1b535bbbb2
commit
4dfcf3e872
@ -364,6 +364,24 @@ def _dict_to_bson(dict):
|
||||
if _use_c:
|
||||
_dict_to_bson = _cbson._dict_to_bson
|
||||
|
||||
def _to_dicts(data):
|
||||
"""Convert binary data to sequence of SON objects.
|
||||
|
||||
Data must be concatenated strings of valid BSON data.
|
||||
|
||||
:Parameters:
|
||||
- `data`: bson data
|
||||
"""
|
||||
dicts = []
|
||||
while len(data):
|
||||
(son, data) = _bson_to_dict(data)
|
||||
dicts.append(son)
|
||||
return dicts
|
||||
|
||||
def _to_dict(data):
|
||||
(son, _) = _bson_to_dict(data)
|
||||
return son
|
||||
|
||||
def is_valid(bson):
|
||||
"""Validate that the given string represents valid BSON data.
|
||||
|
||||
@ -382,20 +400,6 @@ def is_valid(bson):
|
||||
except (AssertionError, InvalidBSON):
|
||||
return False
|
||||
|
||||
def _to_dicts(data):
|
||||
"""Convert binary data to sequence of SON objects.
|
||||
|
||||
Data must be concatenated strings of valid BSON data.
|
||||
|
||||
:Parameters:
|
||||
- `data`: bson data
|
||||
"""
|
||||
dicts = []
|
||||
while len(data):
|
||||
(son, data) = _bson_to_dict(data)
|
||||
dicts.append(son)
|
||||
return dicts
|
||||
|
||||
class BSON(str):
|
||||
"""BSON data.
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ def main():
|
||||
print "enc json",
|
||||
enc_json = run(case, json.dumps)
|
||||
print "dec bson",
|
||||
assert case == run(enc_bson, bson._to_dicts)[0]
|
||||
assert case == run(enc_bson, bson._to_dict)
|
||||
print "dec json",
|
||||
assert case == run(enc_json, json.loads)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user