ucodery / fyeah

Other
23 stars 3 forks source link

complete and CompiledFstring don't speed up f #6

Closed ucodery closed 2 years ago

ucodery commented 2 years ago

I though a compiled code object would speed up the pure python f, but it makes almost no difference.

import timeit

repeat = 1_000_000

print("f-string       :",
    timeit.timeit("f' Hello World, from {me}'",
        setup="me='Monte'", number=repeat))
print("C f-yeah       :",
    timeit.timeit("f(ready)",
        setup="from fyeah._cfyeah import f; me='Monte'; ready=' Hello World, from {me}'", number=repeat))
print("compiled f-yeah:",
    timeit.timeit("f(ready)",
        setup="from fyeah._fyeah import f, compile; me='Monte'; ready=compile(' Hello World, from {me}')", number=repeat))
print("f-yeah         :",
    timeit.timeit("f(ready)",
        setup="from fyeah._fyeah import f; me='Monte'; ready=' Hello World, from {me}'", number=repeat))

outputs

f-string       : 0.086288439
C f-yeah       : 9.101440169
compiled f-yeah: 505.14993312099995
f-yeah         : 507.179490578