Created
January 5, 2018 00:09
-
-
Save rmgimenez/ea2ecf24347f32474c97a8c49d36ce39 to your computer and use it in GitHub Desktop.
Script em python que mostra quanto tempo demorou para executar um script
This file contains 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
""" | |
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