Config

Python Implementation CPython
Python Version 3.11.0b1
Operating System Linux 5.13.0-1023-azure

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Call builtin function 3.13333e-07 1
Calls a local function 3.15e-07 1.00532

TestBasicClassInit🔗

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

Benchmark Min Scaled
Initialize a plain class with slots 2.33333e-07 1
Initialize an attrs class 2.4e-07 1.02857
Initialize a dataclass 2.55e-07 1.09286
Initialize a plain class 2.57895e-07 1.10526
Initialize a typing.TypedDict 3.35e-07 1.43571
Initialize a typing.NamedTuple class 4.2e-07 1.8
Initialize a collections.namedtuple class 4.3e-07 1.84286
Initialize a frozen attrs class 6.57143e-07 2.81633

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 1.34286e-07 1
Access members of a dataclass 1.35294e-07 1.00751
Access members of a plain class with slots 1.36111e-07 1.01359
Access members of an attrs class 1.37143e-07 1.02128
Access members of a frozen attrs class 1.37143e-07 1.02128
Access members of a collections.namedtuple class 1.81481e-07 1.35146
Access members of a typing.NamedTuple class 1.85185e-07 1.37904

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 7e-07 1
Create a dict using keyword arguments 1e-06 1.42857

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.00912809 1
Create a dict from a generator comprehension 0.0137224 1.50331
Create a dict from a list comprehension 0.0210274 2.30359

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.00309734 1
Use filter on list comprehension 0.00784696 2.53345
Use filter on generator comprehension 0.00928492 2.99771

TestLookup🔗

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

Benchmark Min Scaled
Access list values 3.3802e-05 1
Access dict values 7.1203e-05 2.10647

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 2.04167e-07 1
Get a member by converting to a list first 0.000841739 4122.8

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Use `|=` with a set compregension 4.7602e-07 1
Call `set.update` with a set compregension 5.3202e-07 1.11764
Call `set.update` with a list compregension 5.5004e-07 1.1555
Call `set.update` with a generator compregension 5.7802e-07 1.21428

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 8.4e-08 1
Call `set.update` with a generator compregension 9.2e-08 1.09524

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.00134636 1
Merge sets using set(itertools.chain) 0.00277083 2.05801

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 a cached itemgetter 3.4402e-07 1
Split the string using cached slices 4.2e-07 1.22086
Split the string using simple slices 4.7002e-07 1.36626
Split the string using regex 5.8602e-07 1.70345

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.0284231 1
tuple from generator comprehension 0.0406372 1.42973