Skip to content

Commit 0ea2bb9

Browse files
authored
Update benchmark to use PyMongo 4.11 and Python 3.13 (#68)
1 parent 33a7ace commit 0ea2bb9

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

README.rst

+10-9
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ Using bsonjs with pymongo to insert a RawBSONDocument.
5555
Speed
5656
=====
5757

58-
bsonjs is roughly 10-15x faster than PyMongo's json_util at decoding BSON to
58+
bsonjs is roughly 3-4x faster than PyMongo's json_util at decoding BSON to
5959
JSON and encoding JSON to BSON. See `benchmark.py`::
6060

6161
$ python benchmark.py
6262
Timing: bsonjs.dumps(b)
63-
10000 loops, best of 3: 0.110911846161
64-
Timing: json_util.dumps(bson.BSON(b).decode())
65-
10000 loops, best of 3: 1.46571397781
66-
bsonjs is 13.22x faster than json_util
63+
10000 loops, best of 3: 0.04682216700166464
64+
Timing: json_util.dumps(bson.decode(b))
65+
10000 loops, best of 3: 0.17319270805455744
66+
bsonjs is 3.70x faster than json_util
6767

6868
Timing: bsonjs.loads(j)
69-
10000 loops, best of 3: 0.0628039836884
70-
Timing: bson.BSON().encode(json_util.loads(j))
71-
10000 loops, best of 3: 0.683200120926
72-
bsonjs is 11.72x faster than json_util
69+
10000 loops, best of 3: 0.053156834095716476
70+
Timing: bson.encode(json_util.loads(j))
71+
10000 loops, best of 3: 0.15982166700996459
72+
bsonjs is 3.01x faster than json_util
73+
7374

7475
Limitations
7576
===========

benchmark.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ def main(iterations):
5353
" 'date': datetime.datetime(2009, 12, 9, 15),\n"
5454
" 'regex': bson.Regex('.*', 'i'),\n"
5555
"}\n"
56-
"b = bson.BSON.encode(doc)\n"
56+
"b = bson.encode(doc)\n"
5757
"j = bsonjs.dumps(b)\n")
5858

5959
# dumps
6060
compare("bsonjs.dumps(b)",
61-
"json_util.dumps(bson.BSON(b).decode())",
61+
"json_util.dumps(bson.decode(b))",
6262
iterations,
6363
setup)
6464
# loads
6565
compare("bsonjs.loads(j)",
66-
"bson.BSON().encode(json_util.loads(j))",
66+
"bson.encode(json_util.loads(j))",
6767
iterations,
6868
setup)
6969

build-wheels.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ for PYBIN in /opt/python/*/bin; do
4343
fi
4444
"${PYBIN}/pip" install python-bsonjs --no-index -f dist
4545
# The tests require PyMongo.
46-
"${PYBIN}/pip" install 'pymongo>=3.4'
46+
"${PYBIN}/pip" install 'pymongo>=4'
4747
for TEST_FILE in "${BSONJS_SOURCE_DIRECTORY}"/test/test_*.py; do
4848
"${PYBIN}/python" "$TEST_FILE" -v
4949
done

test/test_bsonjs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646

4747
def to_object(bson_bytes):
4848
"""Return deserialized object from BSON bytes"""
49-
return bson.BSON(bson_bytes).decode(CodecOptions(document_class=SON,
50-
tz_aware=True,
51-
uuid_representation=UuidRepresentation.PYTHON_LEGACY))
49+
return bson.decode(bson_bytes, CodecOptions(document_class=SON,
50+
tz_aware=True,
51+
uuid_representation=UuidRepresentation.PYTHON_LEGACY))
5252

5353

5454
def to_bson(obj):
5555
"""Return serialized BSON string from object"""
56-
return bson.BSON.encode(obj, codec_options=CodecOptions(
56+
return bson.encode(obj, codec_options=CodecOptions(
5757
uuid_representation=UuidRepresentation.PYTHON_LEGACY))
5858

5959

0 commit comments

Comments
 (0)