Skip to content

Instantly share code, notes, and snippets.

@jsn1993
Created October 29, 2019 14:09
Show Gist options
  • Save jsn1993/fe044220bed208c9bb31fd4b50e13a81 to your computer and use it in GitHub Desktop.
Save jsn1993/fe044220bed208c9bb31fd4b50e13a81 to your computer and use it in GitHub Desktop.
this code result in a longer trace
# src = """
def compile_funcs(s):
def func1():
s.x += 1
def func2():
s.x += 2
def func3():
s.x += 3
def func4():
s.x += 4
def func5():
s.x += 5
def func6():
s.x += 6
def func7():
s.x += 7
def func8():
s.x += 8
def func9():
s.x += 9
def func10():
s.x += 10
def func11():
s.x += 11
def func12():
s.x += 12
def func13():
s.x += 13
def func14():
s.x += 14
def func15():
s.x += 15
def func16():
s.x += 16
def func17():
s.x += 17
def func18():
s.x += 18
def func19():
s.x += 19
def func20():
s.x += 20
return [ func1, func2, func3, func4, func5, func6, func7, func8, func9, func10,
func11, func12, func13, func14, func15, func16, func17, func18, func19, func20]
# """
class A:
pass
s = A()
s.x = 0
l = compile_funcs(s)
x = 0
def gen(l):
f1 = l[0]
f2 = l[1]
f3 = l[2]
f4 = l[3]
f5 = l[4]
f6 = l[5]
f7 = l[6]
f8 = l[7]
f9 = l[8]
f10 = l[9]
f11 = l[10]
f12 = l[11]
f13 = l[12]
f14 = l[13]
f15 = l[14]
f16 = l[15]
f17 = l[16]
f18 = l[17]
f19 = l[18]
f20 = l[19]
def ab():
f1()
f2()
f3()
f4()
f5()
f6()
f7()
f8()
f9()
f10()
f11()
f12()
f13()
f14()
f15()
f16()
f17()
# f18()
# f19()
# f20()
return ab
ab = gen(l)
def tick():
ab()
for i in range(1000000):
tick()
print(s.x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment