Add more benchmarks

This commit is contained in:
Anthony Shaw
2022-03-03 08:26:43 +11:00
parent d2460dc844
commit f822d1acc1
3 changed files with 52 additions and 10 deletions

View File

@@ -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
View 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"),
]

View File

@@ -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):