f3. (this trivial logic will help with parallelization later)
f3 both mutate
println("\n running f2: ")
println("\n running f3")
for i in 1:n
println("\n running f1")
This is a sample from one iteration:
0.000006 seconds (30 allocations: 4.688 KiB)
0.000005 seconds (1 allocation: 160 bytes)
0.000170 seconds (111 allocations: 8.297 KiB)
Please include all code necessary to reproduce the data (see e.g. Please read: make it easier to help you). Note also that for microbenchmarking you probably want to use the BenchmarkTools.jl package and not
I just don’t know how
f1 can take 1.7e-4 sec when it’s constituents only take 0.1e-4 sec.
You’re measuring printing also. Depending on the terminal, that can be surprisingly slow. You may also be measuring compilation time.
Thanks, I’ll try BenchmarkTools.
I’m not claiming @time is in any way broken, just confused.
I’ll see what I can do as far as an MWE, it’s just that
f3 are both many lines, the structs are very complicated, etc.
Ok, I guess printing could be the culprit. Compilation time unlikely
f1 is getting executed repeatedly in a loop.
Sorry, just realized that the loop structure was excluded, now fixed.
Again I’ll see what I can do about adding MWE
As a side note, you probably want to benchmark this instead of measuring the times only once. You can do that with
using BenchmarkTools and
@btime instead of