Benchmarks#

The benchmarks/ folder contains benchmark tests useful to compare performance against similar libraries such as prodict and dotted-dict.

Quickstart#

First, download the GitHub repo locally with git:

$ git clone https://github.com/rnag/dotwiz
$ cd dotwiz

Ensure you have set up a virtual environment if you haven’t already done so.

Then, use make to install all benchmark and test dependencies:

$ make init

Benchmarking#

Use pytest to benchmark the Python files in this directory.

For example, to benchmark the tests for retrieving keys (via “dot” attribute access):

$ pytest benchmarks -m getattr --benchmark-compare

Pass the --benchmark-histogram argument to generate a histogram for a suite of benchmark tests. For example:

$ pytest benchmarks -m create --benchmark-histogram

To simply run all available benchmark tests:

$ pytest benchmarks

Results#

Here are the benchmark results when running tests against other alternatives or libraries.

dataclasses.make_dataclass#

The results show that loading dict data via an approach with make_dataclass is close to 100x slower than an approach with a dot-access dict subclass such as DotWiz. Also see my post on SO for more info.

This is mainly because with a dict subclass, it doesn’t need to dynamically generate a new class, and scan through the dict object once to generate the dataclass fields and their types.

Though once the class is initially created, I was surprised to find that the dataclass approach performs about 5x better in an average case.

Creating a dot-access dict#

The results indicate it is about 5x faster to create a DotWiz instance (from a dict object) as compared to other competitor libraries such as dotsi and prodict - and up to 15x faster than creating a Box.

Accessing keys by “dot” notation#

The results show it is up to 10x faster to access a key by dot (or attribute) notation than with libraries such as prodict, and about 30x faster than accessing keys from a DotMap for example.