diff --git a/README.rst b/README.rst index 31aed16..6feb7e2 100644 --- a/README.rst +++ b/README.rst @@ -55,21 +55,22 @@ Using bsonjs with pymongo to insert a RawBSONDocument. Speed ===== -bsonjs is roughly 10-15x faster than PyMongo's json_util at decoding BSON to +bsonjs is roughly 3-4x faster than PyMongo's json_util at decoding BSON to JSON and encoding JSON to BSON. See `benchmark.py`:: $ python benchmark.py Timing: bsonjs.dumps(b) - 10000 loops, best of 3: 0.110911846161 - Timing: json_util.dumps(bson.BSON(b).decode()) - 10000 loops, best of 3: 1.46571397781 - bsonjs is 13.22x faster than json_util + 10000 loops, best of 3: 0.04682216700166464 + Timing: json_util.dumps(bson.decode(b)) + 10000 loops, best of 3: 0.17319270805455744 + bsonjs is 3.70x faster than json_util Timing: bsonjs.loads(j) - 10000 loops, best of 3: 0.0628039836884 - Timing: bson.BSON().encode(json_util.loads(j)) - 10000 loops, best of 3: 0.683200120926 - bsonjs is 11.72x faster than json_util + 10000 loops, best of 3: 0.053156834095716476 + Timing: bson.encode(json_util.loads(j)) + 10000 loops, best of 3: 0.15982166700996459 + bsonjs is 3.01x faster than json_util + Limitations =========== diff --git a/benchmark.py b/benchmark.py index ec19635..7d8e96b 100755 --- a/benchmark.py +++ b/benchmark.py @@ -53,17 +53,17 @@ def main(iterations): " 'date': datetime.datetime(2009, 12, 9, 15),\n" " 'regex': bson.Regex('.*', 'i'),\n" "}\n" - "b = bson.BSON.encode(doc)\n" + "b = bson.encode(doc)\n" "j = bsonjs.dumps(b)\n") # dumps compare("bsonjs.dumps(b)", - "json_util.dumps(bson.BSON(b).decode())", + "json_util.dumps(bson.decode(b))", iterations, setup) # loads compare("bsonjs.loads(j)", - "bson.BSON().encode(json_util.loads(j))", + "bson.encode(json_util.loads(j))", iterations, setup) diff --git a/build-wheels.sh b/build-wheels.sh index 1015eff..e5d1e02 100755 --- a/build-wheels.sh +++ b/build-wheels.sh @@ -43,7 +43,7 @@ for PYBIN in /opt/python/*/bin; do fi "${PYBIN}/pip" install python-bsonjs --no-index -f dist # The tests require PyMongo. - "${PYBIN}/pip" install 'pymongo>=3.4' + "${PYBIN}/pip" install 'pymongo>=4' for TEST_FILE in "${BSONJS_SOURCE_DIRECTORY}"/test/test_*.py; do "${PYBIN}/python" "$TEST_FILE" -v done diff --git a/test/test_bsonjs.py b/test/test_bsonjs.py index 965c403..a64e961 100644 --- a/test/test_bsonjs.py +++ b/test/test_bsonjs.py @@ -46,14 +46,14 @@ def to_object(bson_bytes): """Return deserialized object from BSON bytes""" - return bson.BSON(bson_bytes).decode(CodecOptions(document_class=SON, - tz_aware=True, - uuid_representation=UuidRepresentation.PYTHON_LEGACY)) + return bson.decode(bson_bytes, CodecOptions(document_class=SON, + tz_aware=True, + uuid_representation=UuidRepresentation.PYTHON_LEGACY)) def to_bson(obj): """Return serialized BSON string from object""" - return bson.BSON.encode(obj, codec_options=CodecOptions( + return bson.encode(obj, codec_options=CodecOptions( uuid_representation=UuidRepresentation.PYTHON_LEGACY))