Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running time increases for repeated iteration using zsolve. #29

Open
byeongsuyu opened this issue Jun 28, 2020 · 2 comments
Open

Running time increases for repeated iteration using zsolve. #29

byeongsuyu opened this issue Jun 28, 2020 · 2 comments

Comments

@byeongsuyu
Copy link

byeongsuyu commented Jun 28, 2020

I found an interesting phenomenon about "zsolve()" in "4ti2" package in SageMath 9.1. Please see the sample codes, which prints the running time of a function zsolve().

from sage.interfaces.four_ti_2 import four_ti_2
import time
A = [[1,1,1],[1,2,3]]
rel = ['<', '<']
rhs = [2, 3]
sign = [1,1,1]
for i in range(1000):
    start = time.time()
    result=four_ti_2.zsolve(A, rel, rhs, sign)
    print("Running time for zsolve in 4ti2:", time.time()-start," sec")

I expected that except for the first iteration, which needs time for loading the library at first time on the memory, all iterations should take statistically consistent time with some noise following a normal distribution. However, the below chart from the output of the above code shows result different than what I expected.

image description

This graph counts from the second iteration to the last iteration. We can observe that the running time is increasing while the operation itself still the same. Since I'm not an expert in programming so unsure that it is an issue of 4ti2 or python, but I hope to know the reason why this phenomenon happens and how to prevent it to minimize its running time.

Thank you very much for reading this issue.

Byeongsu Yu (byeongsu.yu@math.tamu.edu)

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 28, 2020

Try running the Python garbage collector after each iteration and see if this behavior persists.

@byeongsuyu
Copy link
Author

Try running the Python garbage collector after each iteration and see if this behavior persists.

Thank you for your suggestion. Here is the code using the Garbage collector.

from sage.interfaces.four_ti_2 import four_ti_2
import gc
gc.collect()
import time
A = [[1,1,1],[1,2,3]]
rel = ['<', '<']
rhs = [2, 3]
sign = [1,1,1]
for i in range(1000):
    start = time.time()
    result=four_ti_2.zsolve(A, rel, rhs, sign)
    del result
    gc.collect()
    print("Time for 4ti2:", time.time()-start," sec")

And again I have a similar graph as below.
scr_zsolve_with_gc

For your information, the slope of the linear regression of the above graph is 2.79184e-05, while the slope of the linear regression of the original chart is 2.34818e-05. So using the Garbage Collector make the slope worse than before. I also attached the raw data as CSV file.

Thank you very much for your rapid attention to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants