I need to fix a bottleneck in my code during comparison of an array and a variable.
I’ve tested the map() function and it speed up my code only when I declare the number directly. If I store my number inside a variable I lost the performance.
Below we have a simple example in Julia 0.6.2.
A is just an array and I need to compare it with a value stored in
A = collect(1:1000) + rand(1000); cte = 560.5 @btime A .> 560.5 @btime A .> cte @btime map( (l)-> l > 560.5,A) @btime map( (l)-> l > cte,A)
In my computer, results were:
- 4.679 μs (21 allocations: 5.06 KiB)
- 3.916 μs (21 allocations: 4.95 KiB)
- 846.938 ns (2 allocations: 1.08 KiB)
- 16.998 μs (1003 allocations: 16.72 KiB)
We can see the third line has the better result. How can I define my variable
cte so that the fourth line will had the same performance ?