Config

Python Implementation PyPy
Python Version 3.7.13
Operating System Darwin 20.6.0

Benchmarks

TestCall🔗

Call global or local functions

Benchmark Min Scaled
Calls a local function 1.3605e-09 1
Call builtin function 1.7855e-08 13.1239

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.72e-09 1
Initialize a plain class with slots 9.261e-09 1.06204
Initialize an attrs class 1.063e-08 1.21904
Initialize a dataclass 1.2024e-08 1.3789
Initialize a frozen attrs class 2.88343e-08 3.30669
Initialize a typing.NamedTuple class 3.62313e-08 4.15497
Initialize a collections.namedtuple class 3.66767e-08 4.20604

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.0129e-08 1
Access members of a plain class with slots 2.0886e-08 1.03761
Access members of an attrs class 2.1694e-08 1.07775
Access members of a frozen attrs class 2.2504e-08 1.11799
Access members of a dataclass 2.332e-08 1.15853
Access members of a typing.NamedTuple class 2.57513e-08 1.27931
Access members of a collections.namedtuple class 2.66011e-08 1.32153

TestDictLiteralCreation🔗

Compare different methods of creating a dict literal

Benchmark Min Scaled
Create a dict using a literal 3.594e-06 1
Create a dict using keyword arguments 1.069e-05 2.9744

TestDictComprehension🔗

Compare different comprehensions for dict creation

Benchmark Min Scaled
Create a dict comprehension 0.0115754 1
Create a dict from a generator comprehension 0.0179607 1.55163
Create a dict from a list comprehension 0.0223839 1.93375

TestFilter🔗

Benchmark Min Scaled
Filter in the comprehension 0.00170101 1
Use filter on list comprehension 0.0223754 13.1542
Use filter on generator comprehension 0.0425269 25.001

TestLookup🔗

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

Benchmark Min Scaled
Access list values 1.0242e-05 1
Access dict values 1.7794e-05 1.73736

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.07821e-08 1
Get a member by converting to a list first 0.000155776 5060.61

TestSetUpdateWithGen🔗

Update sets in different ways when generating the additional set

Benchmark Min Scaled
Call `set.update` with a list compregension 2.904e-08 1
Call `set.update` with a set compregension 3.058e-08 1.05303
Use `|=` with a set compregension 3.146e-08 1.08333
Call `set.update` with a generator compregension 5.704e-08 1.96419

TestSetUpdate🔗

Compare set.update and set |=

Benchmark Min Scaled
Use `|=` with a set compregension 3.088e-08 1
Call `set.update` with a generator compregension 4.664e-08 1.51036

TestSetUnion🔗

Test the performance of different ways to unify multiple sets.

Benchmark Min Scaled
Merge sets using set.union 0.00157782 1
Merge sets using set(itertools.chain) 0.0226349 14.3456

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.356e-08 1
Split the string using cached slices 4.768e-08 1.42074
Split the string using a cached itemgetter 1.4856e-07 4.4267
Split the string using regex 1.6442e-07 4.89928

TestTupleComprehension🔗

Compare various ways to write "tuple comprehensions"

Benchmark Min Scaled
tuple from list comprehension 0.065209 1
tuple from generator comprehension 0.0839031 1.28668