# Does compilation time for methods depend on input?

**URL:** <https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440>\
**Category:** Performance\
**Created:** [June 19, 2019, 11:12am UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440 "2019-06-19T11:12:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/srb/32/6812_2.png) [@srb](https://discourse.julialang.org/u/srb)\
**Post date:** [June 19, 2019, 11:12am UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/1 "2019-06-19T11:12:15Z")

</div>

Just a simple questions about compile times,

Say I have a function that takes an Integer argument and does some calculations depending on said integer.

Does the compilation time depend on how big the integer is? Say, for example:

```julia
function f(x::Integer)
    result = 0
    for i in 1:x
        result+=x
    end
end

```

Will it take longer to compile

```julia
f(BigInt(2))

```

vs

```julia
f(BigInt(2)^128)

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 19, 2019, 11:48am UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/2 "2019-06-19T11:48:31Z")

</div>

Compilation depends on input types but not values.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 19, 2019, 11:49am UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/3 "2019-06-19T11:49:43Z")

</div>

I assume that you are talking about compiling `f`, not `f(BigInt(2))`. The former is a function, while the latter is a value.

The compiler doesn’t use the values of your inputs, only the types (except when it comes to constant propagation.) Otherwise, you would have to recompile the code each time you call it with a new value.

There is a slight ambiguity to your question, though. If you actually _mean_ compile `f(BigInt(2))`, for example, if you have a larger code, and `f(BigInt(2))` is on one of those lines, written out with a literal number `2`; then, yes, the compiler might do the job of getting the value of `f(BigInt(2))` or `f(BigInt(2)^128)`, and in that case the difference might change compilation times.

But, most likely, you actually want to know about compiling `f`, not `f(BigInt(2))`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 19, 2019, 11:57am UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/4 "2019-06-19T11:57:18Z")

</div>

> [@ChrisRackauckas](#):
>
> Compilation depends on input types but not values.

I guess this changed a bit with constant propagation, didn’t it? (Not that it would kick in for this example.)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 19, 2019, 12:03pm UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/5 "2019-06-19T12:03:15Z")

</div>

Well yes… but to a first approximation that’s just compiler nonsense 😄

---

<div class="post-metadata">

**Author:** ![srb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/srb/32/6812_2.png) [@srb](https://discourse.julialang.org/u/srb)\
**Post date:** [June 19, 2019, 1:12pm UTC](https://discourse.julialang.org/t/does-compilation-time-for-methods-depend-on-input/25440/6 "2019-06-19T13:12:16Z")

</div>

I know `f(BigInt(2))` is a value, but when you type that into the REPL the function has to be compiled specifically for BigInt arguments. What I wanted to know is if having a bigger value for the argument causes the compilation time for `f` to be longer, but I see it is not the case.
