Last active
August 29, 2015 14:03
-
-
Save alexandre/69fac8eb0df62bab2527 to your computer and use it in GitHub Desktop.
avaliando o tempo de execução entre if e uma expressão booleana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lista para guardar o processo de conversão | |
| conv = [] | |
| def dec2bin(num): | |
| (num / 2 > 0 and (dec2bin(int(num/2)), conv.append(num % 2))) | |
| def dec2bin_if(num): | |
| if num/2 > 0: | |
| dec2bin(int(num / 2)) | |
| conv.append(num % 2) | |
| from timeit import Timer | |
| print ('Sem if: %0.3f' % (Timer("dec2bin({inp})".format(inp=input('Num: ')), | |
| "from __main__ import dec2bin").timeit())) | |
| conv = [] | |
| print ('Com if: %0.3f' % (Timer("dec2bin_if({inp})".format(inp=input('Num: ')), | |
| "from __main__ import dec2bin_if").timeit())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment