Skip to content

Instantly share code, notes, and snippets.

@alexandre
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save alexandre/69fac8eb0df62bab2527 to your computer and use it in GitHub Desktop.

Select an option

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
# 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