Add a globals example

This commit is contained in:
Anthony Shaw
2022-04-21 15:33:22 +10:00
parent 36658391e5
commit c36df62898
2 changed files with 30 additions and 14 deletions

View File

@@ -9,31 +9,26 @@ def keyword_call():
def positional_call():
numbers = (1, 2, 3)
func_with_named_args(a=1, b=2, c=3)
def tiny_func(x, y):
def add(x, y):
return x + y
def use_tiny_func():
x = 1
y = 2
tiny_func(x, y)
tiny_func(x, y)
tiny_func(x, y)
tiny_func(x, y)
tiny_func(x, y)
for n in range(100_000):
add(x, n)
add(n, x)
def inline_tiny_func():
x = 1
y = 2
x + y
x + y
x + y
x + y
x + y
for n in range(100_000):
x + n
n + x
__benchmarks__ = [

21
bench_globals.py Normal file
View File

@@ -0,0 +1,21 @@
MY_GLOBAL_CONSTANT_C = 1234
MY_GLOBAL_CONSTANT_A = 3.14
def global_constant_in_loop():
"""Do a quick sum."""
total = MY_GLOBAL_CONSTANT_A
for i in range(10_000):
total += i * MY_GLOBAL_CONSTANT_C
def local_constant_in_loop():
"""Do a quick sum."""
total = 3.14
for i in range(10_000):
total += i * 1234
__benchmarks__ = [
(global_constant_in_loop, local_constant_in_loop, "Inline globals in loop"),
]