Skip to content

Instantly share code, notes, and snippets.

@Multihuntr
Created July 6, 2020 08:23
Show Gist options
  • Save Multihuntr/3e97ed48d726d0029a994a85a25c98ff to your computer and use it in GitHub Desktop.
Save Multihuntr/3e97ed48d726d0029a994a85a25c98ff to your computer and use it in GitHub Desktop.
Testing scipy linear_sum_assignment speed
FROM python:3.6
RUN pip install numpy scipy
# 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