Add more benchmarks
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"python.linting.banditEnabled": false,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.linting.enabled": true
|
||||
"python.linting.pylintEnabled": false,
|
||||
"python.linting.enabled": false
|
||||
}
|
||||
47
bench_class.py
Normal file
47
bench_class.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
def attributes_in_class():
|
||||
class Pet:
|
||||
legs: int
|
||||
noise: str
|
||||
|
||||
def __init__(self, legs, noise) -> None:
|
||||
self.legs = legs
|
||||
self.noise = noise
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Pet legs={self.legs} noise='{self.noise}'>"
|
||||
|
||||
for _ in range(1000):
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
|
||||
def attributes_in_dataclass():
|
||||
@dataclass
|
||||
class Pet:
|
||||
legs: int
|
||||
noise: str
|
||||
|
||||
for _ in range(1000):
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
|
||||
def attributes_in_namedtuple():
|
||||
Pet = namedtuple("Pet", "legs noise")
|
||||
for _ in range(1000):
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
|
||||
def attributes_in_dict():
|
||||
for _ in range(1000):
|
||||
dog = {"legs": 4, "noise": "woof"}
|
||||
str(dog)
|
||||
|
||||
__benchmarks__ = [
|
||||
(attributes_in_dataclass, attributes_in_class, "Class instead of dataclass"),
|
||||
(attributes_in_dataclass, attributes_in_namedtuple, "Namedtuple instead of dataclass"),
|
||||
(attributes_in_namedtuple, attributes_in_class, "class instead of namedtuple"),
|
||||
(attributes_in_class, attributes_in_dict, "dict instead of class"),
|
||||
]
|
||||
@@ -6,17 +6,12 @@ def func_with_named_args(a, b, c):
|
||||
|
||||
def keyword_call():
|
||||
func_with_kwargs(a=1, b=2, c=3)
|
||||
func_with_kwargs(a=1, b=2, c=3)
|
||||
func_with_kwargs(a=1, b=2, c=3)
|
||||
func_with_kwargs(a=1, b=2, c=3)
|
||||
func_with_kwargs(a=1, b=2, c=3)
|
||||
|
||||
|
||||
def positional_call():
|
||||
numbers = (1, 2, 3)
|
||||
func_with_named_args(a=1, b=2, c=3)
|
||||
func_with_named_args(a=1, b=2, c=3)
|
||||
func_with_named_args(a=1, b=2, c=3)
|
||||
func_with_named_args(a=1, b=2, c=3)
|
||||
func_with_named_args(a=1, b=2, c=3)
|
||||
|
||||
|
||||
|
||||
def tiny_func(x, y):
|
||||
|
||||
Reference in New Issue
Block a user