Config

Python Implementation PyPy
Python Version 3.8.13
Operating System Darwin 20.6.0

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Calls a local function 8.19e-10 1
Call builtin function 1.7643e-08 21.5421

TestBasicClassInit🔗

Compare initialization of different class types. The idea is to compare attrs, dataclasses, and plain classes

Benchmark Min Scaled
Initialize a plain class 8.177e-09 1
Initialize a plain class with slots 8.985e-09 1.09881
Initialize an attrs class 9.804e-09 1.19897
Initialize a dataclass 1.1421e-08 1.39672
Initialize a typing.NamedTuple class 1.223e-08 1.49566
Initialize a collections.namedtuple class 1.3049e-08 1.59582
Initialize a frozen attrs class 3.04161e-08 3.71972
Initialize a typing.TypedDict 6.378e-07 77.9993

TestBasicClassMemberAccess🔗

Compare member access of different class types. The idea is to compare attrs, dataclasses, and plain classes

Benchmark Min Scaled
Access members of a plain class 2.034e-08 1
Access members of a plain class with slots 2.1151e-08 1.03987
Access members of an attrs class 2.1968e-08 1.08004
Access members of a frozen attrs class 2.4213e-08 1.19041
Access members of a dataclass 2.56462e-08 1.26087
Access members of a typing.NamedTuple class 2.7663e-08 1.36003
Access members of a collections.namedtuple class 2.83466e-08 1.39364

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 3.74e-06 1
Create a dict using keyword arguments 8.329e-06 2.22701

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.0121516 1
Create a dict from a generator comprehension 0.014186 1.16742
Create a dict from a list comprehension 0.0153522 1.26339

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.00123291 1
Use filter on list comprehension 0.0210792 17.0972
Use filter on generator comprehension 0.039254 31.8386

TestLookup🔗

Compare using a list or a dict to index-based lookups.

Benchmark Min Scaled
Access list values 8.946e-06 1
Access dict values 1.7458e-05 1.95149

TestSetAccess🔗

Get any item from set

In this case we want to get a single element out of a set. It does not matter which element, but we need one.

Benchmark Min Scaled
Get an item by using iter and next 3.30199e-08 1
Get a member by converting to a list first 0.00016067 4865.86

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Call `set.update` with a list compregension 3.13e-08 1
Call `set.update` with a set compregension 3.282e-08 1.04856
Use `|=` with a set compregension 3.374e-08 1.07796
Call `set.update` with a generator compregension 5.768e-08 1.84281

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 3.156e-08 1
Call `set.update` with a generator compregension 4.676e-08 1.48162

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.00151579 1
Merge sets using set(itertools.chain) 0.0216748 14.2993

TestPairs3🔗

Try and optimiza splitting a 6-character string into a tuple of 3 2-character strings.

This is based on Will McGugan's tweet.

Benchmark Min Scaled
Split the string using simple slices 3.546e-08 1
Split the string using cached slices 5.276e-08 1.48787
Split the string using a cached itemgetter 1.4102e-07 3.97688
Split the string using regex 1.6272e-07 4.58883

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.0631632 1
tuple from generator comprehension 0.11525 1.82464