Config

Python Implementation PyPy
Python Version 3.8.12
Operating System Windows 10

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Calls a local function 2.02e-09 1
Call builtin function 1.84e-08 9.10891

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.5e-09 1
Initialize a plain class with slots 8.9e-09 1.04706
Initialize an attrs class 9.5e-09 1.11765
Initialize a typing.NamedTuple class 1.08e-08 1.27059
Initialize a dataclass 1.11e-08 1.30588
Initialize a collections.namedtuple class 1.25e-08 1.47059
Initialize a frozen attrs class 3.38129e-08 3.97799
Initialize a typing.TypedDict 5.3e-07 62.3529

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.12e-08 1
Access members of a plain class with slots 2.12e-08 1
Access members of an attrs class 2.23301e-08 1.05331
Access members of a dataclass 2.2905e-08 1.08043
Access members of a frozen attrs class 2.3e-08 1.08491
Access members of a typing.NamedTuple class 2.56983e-08 1.21219
Access members of a collections.namedtuple class 2.63158e-08 1.24131

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 3.5e-06 1
Create a dict using keyword arguments 7.6e-06 2.17143

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.0141629 1
Create a dict from a generator comprehension 0.0235076 1.6598
Create a dict from a list comprehension 0.0436533 3.08223

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.0016598 1
Use filter on list comprehension 0.0197968 11.9272
Use filter on generator comprehension 0.0357424 21.5342

TestLookup🔗

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

Benchmark Min Scaled
Access list values 4.25e-06 1
Access dict values 2.13e-05 5.01176

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.09859e-08 1
Get a member by converting to a list first 0.0001556 5021.64

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Call `set.update` with a set compregension 3.2e-08 1
Call `set.update` with a list compregension 3.4e-08 1.0625
Use `|=` with a set compregension 3.4e-08 1.0625
Call `set.update` with a generator compregension 6.6e-08 2.0625

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 3e-08 1
Call `set.update` with a generator compregension 4.6e-08 1.53333

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.0017672 1
Merge sets using set(itertools.chain) 0.0073761 4.17389

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.4e-08 1
Split the string using cached slices 5e-08 1.47059
Split the string using a cached itemgetter 1.48e-07 4.35294
Split the string using regex 1.64e-07 4.82353

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.0413592 1
tuple from generator comprehension 0.170845 4.13076