Oh, by the way, you should use
rand(5000)
instead of
rand(1, 5000)
Julia is column major oriented. I'm a bit surprised it makes so little (or
no) difference here, though. I wonder if the compiler reorganizes it into a
vector or something...
On Friday, September 9, 2016 at 12:21:17 AM UTC+2, DNF wrote:
>
> 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
>>
>>
>>