# What is the proper way to benchmark a using statement?

**URL:** https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029
**Category:** General Usage
**Tags:** question, using
**Created:** [June 19, 2025, 3:09pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029 "2025-06-19T15:09:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)
#### Post date: [June 19, 2025, 3:09pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/1 "2025-06-19T15:09:50Z")

</div>

If calling a `using` statement for the first time since restart, it takes longer than calling after that in a different Julia instance:  
First instance since restart

```julia
julia> @time using SpecialFunctions
  1.596852 seconds (68.60 k allocations: 4.347 MiB, 0.33% compilation time)

```

Second instance

```julia
julia> @time using SpecialFunctions
  0.188694 seconds (84.58 k allocations: 5.072 MiB, 5.71% compilation time)

```

So what is the proper to benchmark the time it takes to call `using` on a module? Do you actually have to restart the computer every time to get an accurate measurement?

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [June 19, 2025, 3:37pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/2 "2025-06-19T15:37:02Z")

</div>

For `using` I would be more interested in the first execution time (time to first plot), because I wouldn’t be `using` a package twice.

---

<div class="post-metadata">

### Author: ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)
#### Post date: [June 19, 2025, 3:47pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/3 "2025-06-19T15:47:29Z")

</div>

That’s the thing. If you restart your computer and `@time` the first `using` in two different Julia processes you will get significantly different times, the first always being much longer than the second like in the above.

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [June 19, 2025, 3:55pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/4 "2025-06-19T15:55:22Z")

</div>

Are you using Windows in a corporate environment by any chance?

I suffered a similar issue (but much worse latency) and concluded it was because of corporate IT security policies. Extended discussion [here](https://discourse.julialang.org/t/investigating-large-latency-on-a-constrained-windows-environment/114482/6).

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [June 19, 2025, 5:33pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/5 "2025-06-19T17:33:37Z")

</div>

I think if you want worst-case measurements, you can start `julia` with [`JULIA_DEPOT_PATH`](https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_DEPOT_PATH) set to a temporary (empty) folder. Then you can `@time` both `Pkg.add("SpecialFunctions")` and `using SpecialFunctions`.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 19, 2025, 6:32pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/6 "2025-06-19T18:32:26Z")

</div>

> [@AwesomeQuest](#):
>
> If you restart your computer and `@time` the first `using` in two different Julia processes you will get significantly different times, the first always being much longer than the second like in the above.

This just sounds like HDD latency, are you using an SSD or HDD?

- [Hard disk drive - Wikipedia](https://en.wikipedia.org/wiki/Hard_disk_drive)

- [Solid-state drive - Wikipedia](https://en.wikipedia.org/wiki/Solid-state_drive)

The second time you do `using`, presumably the data is not read directly from the HDD, rather it’s still cached in RAM.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 19, 2025, 6:35pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/7 "2025-06-19T18:35:48Z")

</div>

> [@AwesomeQuest](#):
>
> So what is the proper to benchmark the time it takes to call `using` on a module?

There are several different things you might wish to measure. This is covered in one subsection of the Performance tips in the Manual:

- [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/#Execution-latency,-package-loading-and-package-precompiling-time)

The in-development version of the docs is more expansive:

- [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1.13-dev/manual/performance-tips/#Execution-latency,-package-loading-and-package-precompiling-time)

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [June 19, 2025, 6:57pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/8 "2025-06-19T18:57:12Z")

</div>

You may also want to try `@time_imports`:

> **[Interactive Utilities · The Julia Language](https://docs.julialang.org/en/v1/stdlib/InteractiveUtils/#Base.%40time_imports)**
>
> Documentation for The Julia Language.

---

<div class="post-metadata">

### Author: ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)
#### Post date: [June 19, 2025, 7:17pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/9 "2025-06-19T19:17:15Z")

</div>

This is the behavior I see on my computer and would explain the different timings in different Julia processes – once Windows has scanned a file, it doesn’t have to intercept read operations from other processes.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [June 19, 2025, 11:40pm UTC](https://discourse.julialang.org/t/what-is-the-proper-way-to-benchmark-a-using-statement/130029/10 "2025-06-19T23:40:52Z")

</div>

> [@mkitti](#):
>
> You may also want to try `@time_imports`:

I don’t see it in the case of `SpecialFunctions`, but sometimes `@time_imports` adds up to more than the first `@time using`. I’m using `Downloads` as an example: 159ms \> 120ms, more or less consistent across several restarts. When I tried this a couple months ago, the difference was even greater (205ms \>\> 74.3ms), which I can’t explain because I was using v1.11.5 both times.

One process:

```julia-auto
julia> @time_imports using Downloads
               ┌ 0.0 ms NetworkOptions. __init__ ()
    115.0 ms NetworkOptions 97.13% compilation time
      9.9 ms ArgTools
               ┌ 0.3 ms nghttp2_jll. __init__ ()
      3.3 ms nghttp2_jll
               ┌ 1.7 ms LibCURL_jll. __init__ ()
      4.6 ms LibCURL_jll
               ┌ 0.0 ms MozillaCACerts_jll. __init__ ()
      4.2 ms MozillaCACerts_jll
               ┌ 0.0 ms LibCURL. __init__ ()
      2.2 ms LibCURL
               ┌ 0.4 ms Downloads.Curl. __init__ ()
     20.0 ms Downloads

julia> +(115,9.9,3.3,4.6,4.2,2.2,20) # ms
159.2

julia> @time_imports using Downloads # already loaded so nothing happens

julia> @time using Downloads # only needs to handle names, 1.3ms
  0.001338 seconds (730 allocations: 46.570 KiB)

```

Another process:

```julia-auto
julia> @time using Downloads # < 0.1592s
  0.119868 seconds (68.07 k allocations: 3.933 MiB, 39.20% gc time)

julia> @time using Downloads # consistent with previous process
  0.001373 seconds (730 allocations: 46.570 KiB)

```

This is unrelated to the timing on first process vs other processes, but I wonder if it could also be explained by interruptions.

> [@nsajko](#):
>
> The second time you do `using`, presumably the data is not read directly from the HDD, rather it’s still cached in RAM.

Can’t test myself because I only have SSDs, but would it be right to presume that the cache is eventually cleared if the OS starts thinking we won’t start Julia anytime soon?
