Performance

python-rapidjson tries to be as performant as possible while staying compatible with the json module.

Tables

The following tables show a comparison between this module and other libraries with different data sets. Last row (“overall”) is the total time taken by all the benchmarks.

Each number shows the factor between the time taken by each contender and python-rapidjson (in other words, they are normalized against a value of 1.0 for python-rapidjson): the lower the number, the speedier the contender.

In bold the winner.

Serialization

serialize

dumps()1

Encoder()2

dumps(n)3

Encoder(n)4

simdjson5

orjson6

ujson7

simplejson8

stdlib9

100 arrays dict

1.00

1.00

0.79

0.78

1.95

0.25

1.05

2.88

1.93

100 dicts array

1.00

0.99

0.84

0.79

1.94

0.33

1.04

3.62

1.94

256 Trues array

1.00

0.99

1.14

0.99

2.23

0.38

1.33

2.63

2.23

256 ascii array

1.00

1.00

1.02

1.00

0.76

0.25

0.43

1.00

0.76

256 doubles array

1.00

1.00

1.01

1.00

0.87

0.06

0.23

0.90

0.86

256 unicode array

1.00

0.84

0.84

0.85

0.66

0.10

0.56

0.78

0.66

apache.json

1.00

0.99

1.01

1.00

1.46

0.30

1.12

1.94

1.45

canada.json

1.00

0.98

0.97

0.97

0.99

0.09

0.32

1.33

0.98

complex object

1.00

1.00

0.93

0.92

1.51

0.26

0.76

1.87

1.50

composite object

1.00

1.02

0.75

0.72

1.82

0.37

0.98

2.36

1.80

ctm.json

1.00

1.00

0.79

0.79

2.00

0.31

1.21

3.12

1.93

github.json

1.00

1.00

0.98

0.97

1.19

0.28

0.90

1.41

1.18

instruments.json

1.00

1.00

0.86

0.86

1.62

0.33

0.99

1.77

1.60

mesh.json

1.00

1.00

0.90

0.91

1.00

0.14

0.35

1.08

0.99

truenull.json

1.00

0.99

1.06

1.03

1.78

0.42

1.48

1.95

1.75

tweet.json

1.00

0.99

1.00

0.96

1.51

0.33

0.92

1.96

1.50

twitter.json

1.00

1.00

0.97

0.97

1.25

0.30

1.00

1.32

1.24

overall

1.00

1.00

0.83

0.83

1.69

0.21

0.86

2.44

1.67

Deserialization

deserialize

loads()10

Decoder()11

loads(n)12

Decoder(n)13

simdjson

orjson

ujson

simplejson

stdlib

100 arrays dict

1.00

1.05

0.95

0.90

0.85

0.73

0.88

1.14

0.93

100 dicts array

1.00

1.00

0.87

0.84

0.62

0.64

0.72

1.33

1.05

256 Trues array

1.00

1.01

1.08

1.01

0.90

0.88

0.80

1.53

1.33

256 ascii array

1.00

1.00

1.03

1.03

0.45

0.75

0.97

0.98

0.84

256 doubles array

1.00

1.00

0.25

0.25

0.20

0.25

0.48

1.12

1.07

256 unicode array

1.00

1.00

1.00

1.00

1.12

0.43

0.97

4.77

1.38

apache.json

1.00

1.00

1.01

1.01

0.65

0.65

0.88

0.93

0.86

canada.json

1.00

0.98

0.31

0.31

0.27

0.33

0.43

1.00

0.91

complex object

1.00

1.01

0.88

0.87

0.66

0.57

0.84

1.18

1.01

composite object

1.00

1.00

0.83

0.82

0.60

0.78

0.61

1.41

1.13

ctm.json

1.00

0.92

0.83

0.84

0.65

0.62

0.92

1.15

1.03

github.json

1.00

1.00

0.98

0.98

0.63

0.63

0.84

0.94

0.85

instruments.json

1.00

1.00

0.86

0.86

0.64

0.55

0.72

1.10

0.92

mesh.json

1.00

0.92

0.47

0.47

0.40

0.49

0.63

1.42

0.95

truenull.json

1.00

1.01

1.09

1.00

0.56

0.95

0.87

1.00

0.86

tweet.json

1.00

1.00

0.98

0.97

0.67

0.64

0.86

1.21

1.08

twitter.json

1.00

1.00

0.95

0.96

0.67

0.62

0.99

1.04

0.99

overall

1.00

1.04

0.89

0.84

0.79

0.69

0.84

1.13

0.93

ASCII vs UTF-8 Serialization

serialize

rj ascii15

rj utf816

uj ascii17

uj utf818

sj ascii19

sj utf820

json ascii21

json utf822

Long ASCII string

1.00

0.40

0.22

0.40

0.62

0.75

0.47

1.13

Long Unicode string

1.00

0.57

0.67

0.62

0.86

0.75

0.74

0.64

overall

1.00

0.51

0.52

0.55

0.78

0.75

0.65

0.80

1

rapidjson.dumps()

2

rapidjson.Encoder()

3

rapidjson.dumps(number_mode=NM_NATIVE)

4

rapidjson.Encoder(number_mode=NM_NATIVE)

5

simdjson 4.0.0

6

orjson 3.5.3

7

ujson 4.0.2

8

simplejson 3.17.2

9

Python 3.9.2 standard library json

10

rapidjson.loads()

11

rapidjson.Decoder()

12

rapidjson.loads(number_mode=NM_NATIVE)

13

rapidjson.Decoder(number_mode=NM_NATIVE)

15

rapidjson.dumps(ensure_ascii=True)

16

rapidjson.dumps(ensure_ascii=False)

17

ujson.dumps(ensure_ascii=True)

18

ujson.dumps(ensure_ascii=False)

19

simplejson.dumps(ensure_ascii=True)

20

simplejson.dumps(ensure_ascii=False)

21

stdlib json.dumps(ensure_ascii=True)

22

stdlib json.dumps(ensure_ascii=False)

DIY

To run these tests yourself, clone the repo and run:

$ make benchmarks

to focus only on RapidJSON or:

$ make benchmarks-others

to get full comparison against other engines.

To reproduce the tables above, run:

$ make benchmarks-tables

Compare different versions

pytest-benchmark implements an handy feature that allows you to weight the impact of a particular change. For example, you may start from a released version and execute:

$ make benchmarks PYTEST_OPTIONS=--benchmark-autosave

After applying whatever change to the code base, you can get a differential view by executing:

$ make benchmarks PYTEST_OPTIONS=--benchmark-compare=0001