If you see the code as @timholy suggested, you will see the knuth shuffle
implementation. Let's capture this as a Julia performance issue on github,
if we can't figure out an easy way to speed this up right away.
-viral
On Saturday, January 23, 2016 at 9:47:21 AM UTC+5:30, Viral Shah wrote:
>
> Generating one by one or together is a small part of the execution time:
>
> julia> @time rand(3*10^8);
> 1.281946 seconds (10 allocations: 2.235 GB, 0.23% gc time)
>
> julia> r(n) = for i=1:n; rand(); end;
> julia> @time r(3*10^8)
> 0.632389 seconds (6 allocations: 192 bytes)
>
> The one by one is perhaps faster because it doesn't have the array
> allocation overhead. So, it
>
>
> -viral
>
> On Saturday, January 23, 2016 at 6:53:38 AM UTC+5:30, Tim Holy wrote:
>>
>> Try
>> @edit randperm(10)
>> and see for yourself.
>>
>> My bet is that you could speed it up by generating all the random numbers
>> you'll need in one go, rather than generating them one-by-one. Want to
>> give it
>> a shot?
>>
>> --Tim
>>
>> On Friday, January 22, 2016 02:54:51 PM Brian Lucena wrote:
>> > I am running a simulation that requires me to generate random
>> permutations
>> > of size 300 million. I would ideally like to run this generation in a
>> loop
>> > 10K or 100K times. I am surprised that randperm is not faster in Julia
>> than
>> > it is. It seems to be considerably slower than the equivalent in R
>> (and R
>> > is clearly not known for speed) :)
>> >
>> > In Julia:
>> >
>> > *julia> **@time asd=randperm(300000000)*
>> >
>> > 43.437829 seconds (6 allocations: 2.235 GB, 0.01% gc time)
>> >
>> > *300000000-element Array{Int64,1}:*
>> >
>> >
>> > In R
>> >
>> > > start = Sys.time()
>> > >
>> > > asd = sample(300000000)
>> > >
>> > > Sys.time()-start
>> >
>> > Time difference of 23.27244 secs
>> >
>> > Julia seems to be twice as slow!
>> >
>> > Any thoughts on why that is? Does randperm use the "knuth shuffle" or
>> does
>> > it use some other algorithm.
>> >
>> > Thanks,
>> > B
>>
>