# \[AMPL 24593\] Differences solver times and real time

**URL:** <https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452>\
**Category:** Google Group Mirror\
**Created:** [March 24, 2023, 3:50am UTC](https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452 "2023-03-24T03:50:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jhoan\_Duque](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jhoan\_Duque](https://discuss.ampl.com/u/Jhoan_Duque)\
**Post date:** [March 24, 2023, 3:50am UTC](https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452/1 "2023-03-24T03:50:33Z")

</div>

Hi AMPL teams,

I am using visual studio community 2022 with API of AMPL for C++ to solve large instances of MIP problems. when calculating the solution time of a large problem, I do it with the c++ chrono commands calculating only the “solve” line (time cpp). and when comparing with the AMPL solver time commands. I find that the closest time to the cpp is the “\_ampl\_elapsed\_time”.

1. Does this last time represent the calculation of the whole AMPL process, from reading, to solving?
2. Why does the “\_total\_solve\_elapsed\_time” differ so much from the real time?

I attach a sample of the time calculation in c++, and a .mod and .dat of a large worked problem

Times:

\_ampl\_elapsed\_time = 4.953  
\_ampl\_system\_time = 0.203125  
\_ampl\_user\_time = 4.67188  
\_ampl\_time = 4.875  
\_shell\_elapsed\_time = 0  
\_shell\_system\_time = 0  
\_shell\_user\_time = 0  
\_shell\_time = 0  
\_solve\_elapsed\_time = 0.156  
\_solve\_system\_time = 0.15625  
\_solve\_user\_time = 0.53125  
\_solve\_time = 0.6875  
\_total\_shell\_elapsed\_time = 0  
\_total\_shell\_system\_time = 0  
\_total\_shell\_user\_time = 0  
\_total\_shell\_time = 0  
\_total\_solve\_elapsed\_time = 0.156  
\_total\_solve\_system\_time = 0.15625  
\_total\_solve\_user\_time = 0.53125  
\_total\_solve\_time = 0.6875

time cpp: 5.101 s.

c++ chrono time:

auto tiniR5 = chrono::high\_resolution\_clock::now(); //inicicializo el tiempo  
ampl.getOutput(“solve;”);  
auto tfinR5 = chrono::high\_resolution\_clock::now(); //inicicializo el tiempo  
double durationauxR5 = chrono::duration\_castchrono::milliseconds (tfinR5 - tiniR5).count() / double(1000);  
cout \<\< durationauxR5 \<\< " ";

_Many thanks in advance for your help._

[Modex.mod](https://discuss.ampl.com/uploads/short-url/8HgNPzCxPrMhZZToSLtVEIzwWnd.mod) (23 KB)

[eje.run](https://discuss.ampl.com/uploads/short-url/9p8xnQ97So5zOJEJmjB1XtQ2Mg0.run) (774 Bytes)

[date.dat](https://discuss.ampl.com/uploads/short-url/5YARFaLwIH1LuUvVp4MQgO5ndep.dat) (33.5 KB)

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [March 25, 2023, 7:43pm UTC](https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452/2 "2023-03-25T19:43:20Z")

</div>

When the AMPL application runs a solver, it spawns a separate solver process, and waits for that process to finish before continuing. Since AMPL and the solver are never running at the same time, their elapsed time can be separated out:

- \_solve\_elapsed\_time = time taken for the most recent solver process
- \_total\_solve\_elapsed\_time = sum of \_solve\_elapsed\_time for all solver processes
- \_ampl\_elapsed\_time = time taken by the AMPL process, not counting any solver process times  
The total elapsed time for an AMPL session is \_ampl\_elapsed\_time + \_total\_solve\_elapsed\_time. In your example this is 4.953 + 0.156 = 5.109 which is consistent with the “time cpp” that you record.

Here are some details to note:

1. Timing starts when the AMPL application begins running, and whenever there is a “reset;”.
2. The \_solve\_time is the sum of the “CPU times” on all of the processor cores. Thus when a solver like CPLEX uses multiple cores in parallel, the \_solve\_elapsed\_time is a much better measure of effectiveness.

---

<div class="post-metadata">

**Author:** ![John\_Matovu](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@John\_Matovu](https://discuss.ampl.com/u/John_Matovu)\
**Post date:** [March 26, 2023, 6:27pm UTC](https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452/3 "2023-03-26T18:27:49Z")

</div>

Is there any package working within AMPL to produce graphs after solving problem. Also related, is there any econometrics package implemented in AMPL that I can use. Am trying to avoid moving around various softwares.

John

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [April 3, 2023, 5:58pm UTC](https://discuss.ampl.com/t/ampl-24593-differences-solver-times-and-real-time/452/4 "2023-04-03T17:58:08Z")

</div>

You will need to provide these facilities from other software. Python, R, and MATLAB are good for these purposes, and there are interfaces (APIs) for connecting AMPL to them; more information is available on our [AMPL APIs](https://ampl.com/products/ampl/apis/) page.
