Created
April 1, 2023 01:20
-
-
Save aphi/4b2f7cfc7ccc52465bead3c24ee9c3f4 to your computer and use it in GitHub Desktop.
Highspy Pybind11 Interface Speed Comparison
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
""" | |
Outputs: | |
Time taken to solve: 10.0589 | |
__getitem__ method for 134322 vars: 162.8729 | |
Copy-first method for 134322 vars: 0.0042 | |
""" | |
import highspy | |
import timeit | |
h = highspy.Highs() | |
h.readModel("bin_packing.mps") | |
h.setOptionValue("time_limit", 10) | |
# Solve | |
start_time = timeit.default_timer() | |
h.run() | |
elapsed = timeit.default_timer() - start_time | |
print(f"Time taken to solve: {elapsed:.4f}") | |
solution = h.getSolution() | |
num_vars = h.getNumCol() | |
# Extract values using __getitem__ N times | |
start_time = timeit.default_timer() | |
values = [solution.col_value[icol] for icol in range(num_vars)] | |
elapsed = timeit.default_timer() - start_time | |
print(f"__getitem__ method for {num_vars} vars: {elapsed:.4f}") | |
# Extract values by copying first to list | |
start_time = timeit.default_timer() | |
col_values = list(solution.col_value) | |
values = [col_values[icol] for icol in range(num_vars)] | |
elapsed = timeit.default_timer() - start_time | |
print(f"Copy-first method for {num_vars} vars: {elapsed:.4f}") |
@HaoZeke Sure, here it is. I zipped it since the full mps file is 30 MB which exceeds GitHub limits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@aphi could you add also the
bin_packing.mps
file needed to reproduce this fully?