Skip to content

Commit

Permalink
Merge pull request #28 from sontek/add_benchmark_for_precise
Browse files Browse the repository at this point in the history
Add benchmark for precise
  • Loading branch information
kenrobbins committed Sep 18, 2015
2 parents cc22b01 + 44d83e2 commit 40f7a64
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ compatible with the ``json`` module. Here are our current benchmarks:
+=========================================+========+============+============+===========+
|Array with 256 doubles | | | | |
+-----------------------------------------+--------+------------+------------+-----------+
| Encode | 13.81s | 12.58s | 1.25s | 8.36s |
| Encode | 13.81s | 12.58s | 1.82s | 8.36s |
+-----------------------------------------+--------+------------+------------+-----------+
| Decode | 1.85s | 4.65s | 0.947s | 2.09s |
| Decode | 2.00s | 4.65s | 2.19s | 2.09s |
+-----------------------------------------+--------+------------+------------+-----------+
| | | | | |
+-----------------------------------------+--------+------------+------------+-----------+
Expand Down
27 changes: 24 additions & 3 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import sys
import random
from functools import partial

try:
import yajl
Expand Down Expand Up @@ -84,10 +85,27 @@ def run_client_test(
contenders.append(('stdlib json', json.dumps, json.loads))

if rapidjson:
contenders.append(('rapidjson', rapidjson.dumps, rapidjson.loads))
contenders.append(
('rapidjson', rapidjson.dumps,
partial(rapidjson.loads, precise_float=True))
)

if ujson:
contenders.append(('ujson', ujson.dumps, ujson.loads))
contenders.append(
('ujson', ujson.dumps, partial(ujson.loads, precise_float=True))
)

unprecise_rapid = (
'rapidjson (not precise)',
rapidjson.dumps,
partial(rapidjson.loads, precise_float=False)
)

unprecise_ujson = (
'ujson (not precise)',
ujson.dumps,
partial(ujson.loads, precise_float=False)
)


doubles = []
Expand Down Expand Up @@ -129,7 +147,10 @@ def test_json_serialization(name, serialize, deserialize):


@pytest.mark.benchmark
@pytest.mark.parametrize('name,serialize,deserialize', contenders)
@pytest.mark.parametrize(
'name,serialize,deserialize',
contenders + [unprecise_ujson, unprecise_rapid]
)
def test_json_doubles(name, serialize, deserialize):
print("\nArray with 256 doubles:")
ser_data, des_data = run_client_test(
Expand Down

0 comments on commit 40f7a64

Please sign in to comment.