๐
Python timeit module
With this module you can get code execution time and compare diffrent implement.
python
from timeit import timeitcode1 = """def xfactor(age):if age <= 0:raise ValueError("Age cannot be 0 or less.")return 10/agetry:xfactor(0)except ValueError as e:pass"""code2 = """def xfactor(age):if age <= 0:return Nonereturn 10/ageXF = xfactor(0)if XF == None:pass"""print("First Code = ", timeit(code1,number=10000))print("Second Code = ", timeit(code2,number=10000))
Output
First Code = 0.007779763999678835Second Code = 0.0016983619998427457
