# CPU time vs Wallclock

**URL:** <https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776>\
**Category:** Optimization (Mathematical)\
**Tags:** question, cplex\
**Created:** [May 27, 2024, 11:11am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776 "2024-05-27T11:11:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShGE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shge/32/207639_2.png) [@ShGE](https://discourse.julialang.org/u/ShGE)\
**Post date:** [May 27, 2024, 11:11am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/1 "2024-05-27T11:11:23Z")

</div>

Hello there  
solve\_time does not return the CPU time even if I set set\_optimizer\_attribute(model, “CPXPARAM\_ClockType”, 1) # CPU clock time  
when using CPLEX.  
is there any way to get CPU time in Jump from whatever solver it is being used !  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 27, 2024, 9:29pm UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/2 "2024-05-27T21:29:27Z")

</div>

If by `solve_time` you mean `JuMP.solve_time(model)`, then yes, this returns the wall clock time.

---

<div class="post-metadata">

**Author:** ![ShGE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shge/32/207639_2.png) [@ShGE](https://discourse.julialang.org/u/ShGE)\
**Post date:** [May 28, 2024, 5:49am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/4 "2024-05-28T05:49:44Z")

</div>

Yeah but how to get the cpu time?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 28, 2024, 7:17am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/5 "2024-05-28T07:17:51Z")

</div>

I’m not aware of any functionality in CPLEX that can return the elapsed CPU time.

See this page from IBM support:

> **[Obtain the elapsed CPU time for CPLEX application](https://www.ibm.com/support/pages/obtain-elapsed-cpu-time-cplex-application)**
>
> How do I obtain the elapsed CPU time for my CPLEX application?

If you can find a way to query it via the C API then please post it below and I can help translate it to Julia.

---

<div class="post-metadata">

**Author:** ![ShGE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shge/32/207639_2.png) [@ShGE](https://discourse.julialang.org/u/ShGE)\
**Post date:** [May 28, 2024, 7:46am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/6 "2024-05-28T07:46:16Z")

</div>

not sure how relates to my question.  
The question is not CPLEX itself which indeed provided the functionality to do that if used via C++ interface.  
The question concerns Jump, how it can get me CPU time.  
Thank you anyway.

---

<div class="post-metadata">

**Author:** ![ShGE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shge/32/207639_2.png) [@ShGE](https://discourse.julialang.org/u/ShGE)\
**Post date:** [May 28, 2024, 7:46am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/7 "2024-05-28T07:46:56Z")

</div>

relevant to my question?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 28, 2024, 8:13am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/8 "2024-05-28T08:13:39Z")

</div>

JuMP does not provide tools to query CPU time. We provide access to wall time.

To get the CPU time, you would need to query the solver. JuMP does not know, for example, how many cores the solver used. CPLEX does not provide this information. (But other solvers may do.)

Why do you need CPU time? In almost every case, wall time is a better measure.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 28, 2024, 8:48am UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/9 "2024-05-28T08:48:17Z")

</div>

> CPLEX itself which indeed provided the functionality to do that if used via C++ interface.

What was the syntax? Is it available via the C API?

---

<div class="post-metadata">

**Author:** ![ShGE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shge/32/207639_2.png) [@ShGE](https://discourse.julialang.org/u/ShGE)\
**Post date:** [May 28, 2024, 1:17pm UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/10 "2024-05-28T13:17:03Z")

</div>

Ilocplex: getCplexTime.  
The clock type also needs to be set.  
It is only for C++ interface as far as I know

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 28, 2024, 9:40pm UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/11 "2024-05-28T21:40:57Z")

</div>

It looks like there is [https://www.ibm.com/docs/en/icos/20.1.0?topic=g-cpxxgettime-cpxgettime](https://www.ibm.com/docs/en/icos/20.1.0?topic=g-cpxxgettime-cpxgettime), so you could do:

```julia
julia> using JuMP, CPLEX

julia> function get_time(model::JuMP.Model)
           cpx = unsafe_backend(model)
           timestamp_p = Ref{Cdouble}()
           ret = CPLEX.CPXgettime(cpx.env, timestamp_p)
           @assert ret == 0
           return timestamp_p[]
       end
get_time (generic function with 1 method)

julia> model = Model(CPLEX.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: CPLEX

julia> @variable(model, x >= 0)
x

julia> set_attribute(model, "CPXPARAM_ClockType", 1)

julia> start_time = get_time(model)
13.19

julia> optimize!(model)
CPLEX Error 3003: Not a mixed-integer problem.
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de
CPXPARAM_ClockType 1
Tried aggregator 1 time.
LP Presolve eliminated 0 rows and 1 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.00 ticks)

julia> run_time = get_time(model) - start_time
0.0

```

I don’t know what the resolution is though.

---

<div class="post-metadata">

**Author:** ![fstwn](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fstwn](https://discourse.julialang.org/u/fstwn)\
**Post date:** [February 26, 2025, 12:56pm UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/12 "2025-02-26T12:56:49Z")

</div>

Hi @odow, what is the difference between CPU time and wall clock time in CPLEX? Why did you say that wall time is a better measure?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 26, 2025, 5:41pm UTC](https://discourse.julialang.org/t/cpu-time-vs-wallclock/114776/13 "2025-02-26T17:41:07Z")

</div>

See [Elapsed real time - Wikipedia](https://en.m.wikipedia.org/wiki/Elapsed_real_time)
