# Understanding performance using \`@btime\` and \`@code\_warntype\`, \`@code\_llvm\`, etc

**URL:** https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293
**Category:** Performance
**Created:** [October 13, 2018, 9:51pm UTC](https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293 "2018-10-13T21:51:12Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [October 14, 2018, 7:38am UTC](https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293/2 "2018-10-14T07:38:14Z")

</div>

String interpolation (used [here](https://github.com/JuliaStats/Distributions.jl/blob/7efc1d53a5ab55f3060bb34982e68e1ebce32f5a/src/utils.jl#L3-L10)) forces the allocation of the gcframe. There’s a standard trick for avoiding this problem: instead of

```julia
function mysqrt(x)
    x >= 0 || throw(ArgumentError("x must be positive, got $x"))
    sqrt(x)
end

```

do something like this:

```julia
function mysqrt(x)
    nonpos(x) = throw(ArgumentError("x must be positive, got $x"))
    x >= 0 || nonpos(x)
    sqrt(x)
end

```

By putting the error message generation in a separate function you ensure the gcframe gets allocated only in the error condition. In other people’s code (esp. older code) you may sometimes see `@noinline` in front of `nonpos`, because of course this trick fails if `nonpos` gets inlined into `mysqrt`; however, from 0.7 julia’s compiler is smart enough to figure that out on its own.

---

_[View the full topic](https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293)._
