On Thu, Sep 8, 2016 at 12:11 PM, Yichao Yu <[email protected]> wrote:

>
> On Thu, Sep 8, 2016 at 12:03 PM, Dupont <[email protected]> wrote:
>
>>
>> function essai(n,s1,s2)
>>   a = zeros(Int64,n)
>>   ss1::Float64 = 0.
>>   ss2::Float64 = 0.
>>   @inbounds begin
>>     for k=1:n
>>       for i=1:length(s1)
>>         ss1 = s1[i]
>>         for j=1:length(s2)
>>           ss2 = s2[j]
>>           if ss1>ss2
>>             a[k] += 1
>>           end
>>         end
>>       end
>>     end
>>   end
>> end
>>
>> a = rand(1,5000)
>> b = rand(1,5000)
>> essai(1,a,b)
>> @time essai(200,a,b)
>>
>
>
> function essai(n,s1,s2)
>     a = zeros(Int64,n)
>     ss1::Float64 = 0.
>     ss2::Float64 = 0.
>     @inbounds for k = 1:n
>         ak = a[k]
>         for i = 1:length(s1)
>             ss1 = s1[i]
>             for j = 1:length(s2)
>                 ak += ss1 > s2[j]
>             end
>         end
>         a[k] = ak
>     end
> end
>

And just to make the code cleaner/shorter

function essai(n, s1, s2)
    a = Vector{Int64}(n)
    @inbounds for k = 1:n
        ak = 0
        for ss1 in s1, ss2 in s2
            ak += ss1 > ss2
        end
        a[k] = ak
    end
end

Reply via email to