add execution time measuring
This commit is contained in:
parent
3e8103fd39
commit
d4380883b2
@ -1,2 +1,3 @@
|
|||||||
from .inputs import *
|
from .inputs import *
|
||||||
from .output import *
|
from .output import *
|
||||||
|
from .performance import *
|
||||||
|
|||||||
13
aoclib/performance.py
Normal file
13
aoclib/performance.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def print_execution_time(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
time_start = time.time()
|
||||||
|
return_value = func(*args, **kwargs)
|
||||||
|
time_stop = time.time()
|
||||||
|
print('{:s} function took {:.3f}ms'.format(func.__name__, (time_stop - time_start) * 1000.0))
|
||||||
|
|
||||||
|
return return_value
|
||||||
|
|
||||||
|
return wrapper
|
||||||
2
day01.py
2
day01.py
@ -17,11 +17,13 @@ def getProductOf2020Sum(input_lines, combinations):
|
|||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part1(test_mode=False):
|
def part1(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
||||||
return getProductOf2020Sum(my_input, 2)
|
return getProductOf2020Sum(my_input, 2)
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part2(test_mode=False):
|
def part2(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
||||||
return getProductOf2020Sum(my_input, 3)
|
return getProductOf2020Sum(my_input, 3)
|
||||||
|
|||||||
2
day02.py
2
day02.py
@ -6,6 +6,7 @@ DAY = 2
|
|||||||
splitter = re.compile(r'([0-9]+)-([0-9]+) ([a-z]): (.*)')
|
splitter = re.compile(r'([0-9]+)-([0-9]+) ([a-z]): (.*)')
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part1(test_mode=False):
|
def part1(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=2, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=2, test=test_mode)
|
||||||
valid_count = 0
|
valid_count = 0
|
||||||
@ -18,6 +19,7 @@ def part1(test_mode=False):
|
|||||||
return valid_count
|
return valid_count
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part2(test_mode=False):
|
def part2(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=2, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=2, test=test_mode)
|
||||||
valid_count = 0
|
valid_count = 0
|
||||||
|
|||||||
2
day03.py
2
day03.py
@ -19,11 +19,13 @@ def check_for_trees(right_step, down_step, treelines):
|
|||||||
return tree_count
|
return tree_count
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part1(test_mode=False):
|
def part1(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
|
||||||
return check_for_trees(3, 1, my_input)
|
return check_for_trees(3, 1, my_input)
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part2(test_mode=False):
|
def part2(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
|
||||||
tree_count1 = check_for_trees(1, 1, my_input)
|
tree_count1 = check_for_trees(1, 1, my_input)
|
||||||
|
|||||||
2
day04.py
2
day04.py
@ -70,6 +70,7 @@ def verifyPassportData(passport_data, verify_data=False):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part1(test_mode=False):
|
def part1(test_mode=False):
|
||||||
valid = 0
|
valid = 0
|
||||||
for passport_line in aoclib.getMultiLineInputAsArray(day=4, test=test_mode):
|
for passport_line in aoclib.getMultiLineInputAsArray(day=4, test=test_mode):
|
||||||
@ -80,6 +81,7 @@ def part1(test_mode=False):
|
|||||||
return valid
|
return valid
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part2(test_mode=False):
|
def part2(test_mode=False):
|
||||||
valid = 0
|
valid = 0
|
||||||
for passport_line in aoclib.getMultiLineInputAsArray(day=4, test=test_mode):
|
for passport_line in aoclib.getMultiLineInputAsArray(day=4, test=test_mode):
|
||||||
|
|||||||
8
day05.py
8
day05.py
@ -2,6 +2,8 @@
|
|||||||
import aoclib
|
import aoclib
|
||||||
|
|
||||||
DAY = 5
|
DAY = 5
|
||||||
|
rows_predefined = list(range(0, 128))
|
||||||
|
columns_predefined = list(range(0, 8))
|
||||||
|
|
||||||
|
|
||||||
def getSeatRowColumn(seat_string):
|
def getSeatRowColumn(seat_string):
|
||||||
@ -11,7 +13,7 @@ def getSeatRowColumn(seat_string):
|
|||||||
row_string = seat_string[:7]
|
row_string = seat_string[:7]
|
||||||
column_string = seat_string[-3:]
|
column_string = seat_string[-3:]
|
||||||
|
|
||||||
rows = list(range(0, 128))
|
rows = rows_predefined.copy()
|
||||||
for row_char in row_string:
|
for row_char in row_string:
|
||||||
if row_char == 'F':
|
if row_char == 'F':
|
||||||
rows = rows[:int(len(rows) / 2)]
|
rows = rows[:int(len(rows) / 2)]
|
||||||
@ -21,7 +23,7 @@ def getSeatRowColumn(seat_string):
|
|||||||
if len(rows) > 1:
|
if len(rows) > 1:
|
||||||
raise ValueError('left with more than one row: %s' % rows)
|
raise ValueError('left with more than one row: %s' % rows)
|
||||||
|
|
||||||
columns = list(range(0, 8))
|
columns = columns_predefined.copy()
|
||||||
for column_char in column_string:
|
for column_char in column_string:
|
||||||
if column_char == 'L':
|
if column_char == 'L':
|
||||||
columns = columns[:int(len(columns) / 2)]
|
columns = columns[:int(len(columns) / 2)]
|
||||||
@ -38,6 +40,7 @@ def getSeatID(row, column):
|
|||||||
return row * 8 + column
|
return row * 8 + column
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part1(test_mode=False):
|
def part1(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=5, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=5, test=test_mode)
|
||||||
max_id = 0
|
max_id = 0
|
||||||
@ -48,6 +51,7 @@ def part1(test_mode=False):
|
|||||||
return max_id
|
return max_id
|
||||||
|
|
||||||
|
|
||||||
|
@aoclib.print_execution_time
|
||||||
def part2(test_mode=False):
|
def part2(test_mode=False):
|
||||||
my_input = aoclib.getInputAsArray(day=5, test=test_mode)
|
my_input = aoclib.getInputAsArray(day=5, test=test_mode)
|
||||||
seat_list = list(range(0, 1024))
|
seat_list = list(range(0, 1024))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user