Closed tweakimp closed 4 years ago
I didn't notice this but it's an interesting found with timeit
>>> timeit.timeit('int(3 // 2 + bool(3 % 2))', number=100000)
0.026131337999970583
>>> timeit.timeit('ceil(3 / 2)', number=100000, setup="from math import ceil")
0.009041516000024785
>>> timeit.timeit('3 // 2', number=100000)
0.0008856160000050295
>>> timeit.timeit('floor(3 / 2)', number=100000, setup="from math import floor")
0.008675524000011592
Ok, but note this:
import math
floor = lambda a, b: a // b
x = 10
y = 3.4
print(type(math.floor(x / y))) # <class 'int'>
print(type(floor(x, y))) # <class 'float'>
I made METHOD_MAPPING global so that it is only created one time during loading time. Also
math.ceil
is used to replace the ceil function you wrote. :)block_iter
is a generator now.