# Time to first plot benchmark

**URL:** https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726
**Category:** General Usage
**Tags:** package, ttfp
**Created:** [July 24, 2019, 9:44am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726 "2019-07-24T09:44:02Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 9:44am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/1 "2019-07-24T09:44:02Z")

</div>

In the light of Julia survey result (i.e people complain about time to the first plot), I did a naive benchmark, as expected, PyPlot is the fastest ☹

[http://uaf-8.t2.ucsd.edu/~jling/dump/PlotBenchmark.html](http://uaf-8.t2.ucsd.edu/~jling/dump/PlotBenchmark.html)

Because it takes some time to `display` the image (`@time` will appear way before image actually shows up), I chose to do put the timing like this which is a bit hacky – you need to hit `restart kernel and run all cells`.

To my surprise, Gadfly is slower than Plots.

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [July 24, 2019, 10:01am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/2 "2019-07-24T10:01:59Z")

</div>

You should add the line

```julia
t = time(); Plots.GR.histogram(a);println("Plain GR used $(time() - t)s")

```

to measure the plain GR performance. 😄

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 10:35am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/3 "2019-07-24T10:35:30Z")

</div>

good point, updated! `GR` is pretty fast 😉

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 10:41am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/4 "2019-07-24T10:41:04Z")

</div>

for fair comparison, now they have the same `nbins=20`

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [July 24, 2019, 10:51am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/5 "2019-07-24T10:51:48Z")

</div>

… but you are still measuring some `Plots` overhead. The first time to plot (with plain GR) should be about 2-3 seconds.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 10:52am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/6 "2019-07-24T10:52:26Z")

</div>

where is the Plots overhead?

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [July 24, 2019, 11:23am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/7 "2019-07-24T11:23:29Z")

</div>

Not sure, but could you try

```julia
julia> @time using GR
  0.183892 seconds (83.67 k allocations: 5.665 MiB)

julia> @time histogram(randn(10000), nbins=50)
  3.965902 seconds (8.77 M allocations: 442.108 MiB, 5.76% gc time)

```

on your machine. My laptop is old and slow … 😥

The above result are Julia 1.3.0-alpha.1 on macOS Catalina 10.15.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 11:35am UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/8 "2019-07-24T11:35:43Z")

</div>

I noticed in Jupyter there’s delay between cell calls, fixed that, still ~4s.

The thing is, `@time` does NOT reflect the time it takes for you to see the plot, you can try this in Jupyter notebook. when `@time` spits out the answer, you haven’t seen the plot yet.

```julia
julia> @time using GR  
0.194347 seconds (159.49 k allocations: 10.088 MiB)

julia> @time histogram(randn(10000), nbins=50)  
3.863596 seconds (10.47 M allocations: 524.561 MiB, 6.45% gc time)

julia> versioninfo()
Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 7

```

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [July 24, 2019, 12:30pm UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/9 "2019-07-24T12:30:37Z")

</div>

Ok, then it’s probably better to perform the benchmarks in a simple shell environment …

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 12:57pm UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/10 "2019-07-24T12:57:41Z")

</div>

Then how does that reflect real world speed?

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [July 24, 2019, 2:06pm UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/11 "2019-07-24T14:06:10Z")

</div>

try `@time display(plot(...))`

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [July 24, 2019, 3:42pm UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726/12 "2019-07-24T15:42:55Z")

</div>

That does work, but Gadfly would open a new tab instead of doing it inline. The time measured that way is close to the current ones.
