Config

Python Implementation PyPy
Python Version 3.7.13
Operating System Windows 10

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Calls a local function 1.48e-09 1
Call builtin function 1.58e-08 10.6757

TestBasicClassInit🔗

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

Benchmark Min Scaled
Initialize a plain class 7.3e-09 1
Initialize a plain class with slots 7.7e-09 1.05479
Initialize an attrs class 8.5e-09 1.16438
Initialize a dataclass 9.7e-09 1.32877
Initialize a frozen attrs class 2.65957e-08 3.64325
Initialize a typing.NamedTuple class 3.40136e-08 4.6594
Initialize a collections.namedtuple class 3.52113e-08 4.82346

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.85e-08 1
Access members of a plain class with slots 1.87e-08 1.01081
Access members of a frozen attrs class 2e-08 1.08108
Access members of an attrs class 2.03e-08 1.0973
Access members of a dataclass 2.21e-08 1.19459
Access members of a typing.NamedTuple class 2.33e-08 1.25946
Access members of a collections.namedtuple class 2.46305e-08 1.33138

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 2.5e-06 1
Create a dict using keyword arguments 5.6e-06 2.24

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.0119235 1
Create a dict from a list comprehension 0.0147055 1.23332
Create a dict from a generator comprehension 0.0295004 2.47414

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.001331 1
Use filter on list comprehension 0.0165267 12.4168
Use filter on generator comprehension 0.0281838 21.1749

TestLookup🔗

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

Benchmark Min Scaled
Access list values 3.1e-06 1
Access dict values 1.79e-05 5.77419

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.12102e-08 1
Get a member by converting to a list first 0.0001422 4556.2

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Call `set.update` with a set compregension 3e-08 1
Call `set.update` with a list compregension 3.2e-08 1.06667
Use `|=` with a set compregension 3.2e-08 1.06667
Call `set.update` with a generator compregension 6e-08 2

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 2.6e-08 1
Call `set.update` with a generator compregension 4.4e-08 1.69231

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.0011939 1
Merge sets using set(itertools.chain) 0.0054845 4.59377

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 4.6e-08 1.35294
Split the string using a cached itemgetter 1.26e-07 3.70588
Split the string using regex 1.52e-07 4.47059

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.0327397 1
tuple from generator comprehension 0.12037 3.67657