Add some extra benchmarks
This commit is contained in:
15
bench_comprehensions.py
Normal file
15
bench_comprehensions.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def filter_list_as_loop():
|
||||
result = []
|
||||
inputs = range(100_000)
|
||||
for i in inputs:
|
||||
if i % 2:
|
||||
result.append(i)
|
||||
|
||||
def filter_list_as_comprehension():
|
||||
inputs = range(100_000)
|
||||
result = [i for i in inputs if i % 2]
|
||||
|
||||
|
||||
__benchmarks__ = [
|
||||
(filter_list_as_loop, filter_list_as_comprehension, "Using a list comprehension to filter another list"),
|
||||
]
|
||||
24
bench_try.py
Normal file
24
bench_try.py
Normal file
@@ -0,0 +1,24 @@
|
||||
def try_in_loop():
|
||||
items = {
|
||||
'a': 1
|
||||
}
|
||||
for _ in range(100_000):
|
||||
try:
|
||||
_ = items['a']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def try_outside_loop():
|
||||
items = {
|
||||
'a': 1
|
||||
}
|
||||
try:
|
||||
for _ in range(100_000):
|
||||
_ = items['a']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
__benchmarks__ = [
|
||||
(try_in_loop, try_outside_loop, "Refactoring Try..except outside a loop"),
|
||||
]
|
||||
Reference in New Issue
Block a user