Watch this.

We define an array:
a = collect(-1:0.001:1)

Then map something over the aforementioned array for the first time:
@time map(x->10^x, a) 
# 0.049258 seconds

Do it again so that we don't capture JIT compilation time:
@time map(x->10^x, a) 
# *0.048793 seconds* -- didn't change much

Now we assign the anonymous function to a variable:
f = x->10^x

Then we map the variable over the array:
@time map(f, a)
# 0.047853 seconds

Again so that we avoid JIT:
@time map(f, a)
# *0.000386 seconds *-- wow

What is happening here?
Why does assigning an anonymous function to a variable makes the function 
execution so much faster?


Yousef

Reply via email to