-
-
Save Multihuntr/3e97ed48d726d0029a994a85a25c98ff to your computer and use it in GitHub Desktop.
Testing scipy linear_sum_assignment speed
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
FROM python:3.6 | |
RUN pip install numpy scipy |
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
# Based on python test https://github.com/Yay295/AssignmentProblemComparison/blob/master/BrianMClapper/SpeedTest.py | |
# In https://github.com/Yay295/AssignmentProblemComparison | |
import numpy as np | |
import scipy as sp | |
from scipy import optimize | |
import random, time | |
np.random.seed(100) | |
tests = ( | |
# todo, size | |
(10000,50), | |
(100,250), | |
(10,1000) | |
) | |
THOUSAND = 1000 | |
MILLION = THOUSAND * THOUSAND | |
BILLION = MILLION * THOUSAND | |
for todo, size in tests: | |
max_size = size * size | |
total_time = 0 | |
for total in range(1,todo+1): | |
matrix = np.random.randint(0, max_size, size=[size, size]) | |
if (total < 12): print(total, matrix.sum()) | |
elif (total < 100 and total % 12 == 0): print(total / 12, " Dozen") | |
elif (total < THOUSAND and total % 100 == 0): print(total / 100, " Hundred") | |
elif (total < MILLION and total % THOUSAND == 0): print(total / THOUSAND, " Thousand") | |
elif (total < BILLION and total % MILLION == 0): print(total / MILLION, " Million") | |
elif (total % BILLION == 0): print(total / BILLION, " Billion") | |
start = time.time() | |
sp.optimize.linear_sum_assignment(matrix) | |
end = time.time() | |
total_time += end - start | |
print('\nAverage Time (', size, 'x', size, '):', total_time / todo, '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment