Config

Python Implementation PyPy
Python Version 3.7.13
Operating System Linux 5.13.0-1023-azure

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Calls a local function 1.51e-09 1
Call builtin function 2.38e-08 15.7616

TestBasicClassInit🔗

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

Benchmark Min Scaled
Initialize a plain class 1.11e-08 1
Initialize a plain class with slots 1.11e-08 1
Initialize an attrs class 1.14e-08 1.02703
Initialize a dataclass 1.34e-08 1.20721
Initialize a frozen attrs class 2.85714e-08 2.574
Initialize a typing.NamedTuple class 3.66906e-08 3.30546
Initialize a collections.namedtuple class 3.77778e-08 3.4034

TestBasicClassMemberAccess🔗

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

Benchmark Min Scaled
Access members of an attrs class 2.5641e-08 1
Access members of a plain class 2.63158e-08 1.02632
Access members of a plain class with slots 2.74194e-08 1.06935
Access members of a dataclass 2.78689e-08 1.08689
Access members of a frozen attrs class 2.7933e-08 1.08939
Access members of a typing.NamedTuple class 2.97619e-08 1.16071
Access members of a collections.namedtuple class 3.26797e-08 1.27451

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 1.8e-06 1
Create a dict using keyword arguments 4e-06 2.22222

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.00977206 1
Create a dict from a list comprehension 0.012383 1.26718
Create a dict from a generator comprehension 0.0378092 3.86912

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.00127271 1
Use filter on list comprehension 0.0159614 12.5413
Use filter on generator comprehension 0.0300767 23.632

TestLookup🔗

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

Benchmark Min Scaled
Access list values 2.95e-06 1
Access dict values 1.49e-05 5.05085

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.42282e-08 1
Get a member by converting to a list first 0.000160201 4680.38

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Call `set.update` with a list compregension 3e-08 1
Use `|=` with a set compregension 3.2e-08 1.06667
Call `set.update` with a set compregension 3.4e-08 1.13333
Call `set.update` with a generator compregension 5.6e-08 1.86667

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 3.4e-08 1
Call `set.update` with a generator compregension 4.402e-08 1.29471

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.000838905 1
Merge sets using set(itertools.chain) 0.00410503 4.89331

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.6e-08 1
Split the string using cached slices 4.8e-08 1.33333
Split the string using a cached itemgetter 1.36e-07 3.77778
Split the string using regex 1.5e-07 4.16667

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.02685 1
tuple from generator comprehension 0.0474198 1.7661