Skip to content

Instantly share code, notes, and snippets.

@rmgimenez
Created January 5, 2018 00:09
Show Gist options
  • Save rmgimenez/ea2ecf24347f32474c97a8c49d36ce39 to your computer and use it in GitHub Desktop.
Save rmgimenez/ea2ecf24347f32474c97a8c49d36ce39 to your computer and use it in GitHub Desktop.
Script em python que mostra quanto tempo demorou para executar um script
"""
ExecutionTime
This class is used for timing execution of code.
For example:
timer = ExecutionTime()
print 'Hello world!'
print 'Finished in {} seconds.'.format(timer.duration())
"""
import time
import random
class ExecutionTime:
def __init__(self):
self.start_time = time.time()
def duration(self):
return time.time() - self.start_time
# ---- run code ---- #
timer = ExecutionTime()
sample_list = list()
my_list = [random.randint(1, 8828898) for num in
range(1, 1000000) if num % 2 == 0]
print('Finished in {} seconds.'.format(timer.duration()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment