If you change your test to
a = rand(1,5000)
b = rand(1,5000) + 1
you will see significant speedup of you original code. This is a branch
prediction problem, isn't it? You are branching on the comparison of two
random vectors, that is the hardest thing you can ask for. Prediction will
be wrong half the time. If you increase the value of one of the vectors
prediction will be right pretty much all the time.
If on the other hand, you use
a += ss1 > ss2
there is no branch at all, and there is no decision on which branch to take.
On Thursday, September 8, 2016 at 9:45:30 PM UTC+2, Dupont wrote:
>
> What is strange to me is that this is much slower
>
>
> function essai(n, s1, s2)
> a = Vector{Int64}(n)
>
> @inbounds for k = 1:n
> ak = 0
> for ss1 in s1, ss2 in s2
> if ss1 > ss2
> ak += 1
> end
> end
> a[k] = ak
> end
> end
>
>
>