Thanks Derek, I may be running quite a few iterations so I'll see if GSL can be easily installed.
Cheers, Nick On Thursday, 6 August 2015, Derek Lamb <[email protected]> wrote: > Hi Nick, > > You don't have to guess which one seems to be quicker, you can Benchmark > this directly on whatever machine you'll be doing the computations. On my > machine, GSL is by far the fastest (3.5x faster than the next), followed by > Marek's solution, then David's. Of course, if you're only doing a few > thousand, then downloading and installing GSL if it isn't already present > (or even just running the benchmark in the first place!) will take much > more than the ~10 seconds you'll save. But if you're going to be doing > millions or billions of iterations, or need access to different RNGs, GSL > might be worth the extra overhead. > > best, > Derek > > CODE: > use Benchmark; > use PDL::GSL::RNG; > $data = sequence(1500); > $r = PDL::GSL::RNG->new('taus'); > timethese(5e4, { > David=>sub{cat(random($data),$data)->transpose->qsortvec->(1)->flat;}, > Marek=>sub{$data(qsorti(random($data)));}, > GSL=>sub{$r->ran_shuffle($data);} > }); > > OUTPUT: > Benchmark: timing 50000 iterations of David, GSL, Marek... > David: 17 wallclock secs (16.39 usr + 0.06 sys = 16.45 CPU) @ > 3039.51/s (n=50000) > GSL: 3 wallclock secs ( 2.66 usr + 0.01 sys = 2.67 CPU) @ > 18726.59/s (n=50000) > Marek: 9 wallclock secs ( 9.58 usr + 0.03 sys = 9.61 CPU) @ > 5202.91/s (n=50000) > > > On Aug 6, 2015, at 11:23 AM, Nick Wright <[email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote: > > Hi everyone > > Thank you all for your quick replies! > > I've given Marek and David's suggestions a try and both seem to work > (David I had to edit yours to be $shuffled = $data -> > index(qsorti(random($data))), was that what you meant? It gave a > compilation error otherwise). Both are very quick and do exactly what I > wanted, thank you both - David's appears to be a bit quicker so I expect > I'll use that. > > Thanks for all the other suggestions as well, there's some things there > I'll investigate once I set this running. > > Cheers, > > Nick > > On 6 August 2015 at 18:14, vividsnow <[email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote: > >> hi >> >> use PDL::GSL::RNG; >> $p = sequence(100); >> $r = PDL::GSL::RNG->new('taus'); >> $r->ran_shuffle($p); >> p $p; >> >> On 08/06/2015 07:59 PM, Nick Wright wrote: >> > Hi everyone >> > >> > I need help with something that I think *should* be simple with >> Perl/PDL but I can't find the command for it. >> > >> > I basically just want to randomly re-order a 1-dimensional, moderately >> long (1500 entries) piddle and I can't find a simple way. I need to do this >> for the purposes of a Monte Carlo simulation, so I was hoping PDL might >> have an efficient way to do it so I can repeat is 1000s of times quickly! >> > >> > Thanks in advance for the help! >> > >> > Cheers, >> > >> > Nick >> > >> > >> > >> ------------------------------------------------------------------------------ >> > >> > >> > >> > _______________________________________________ >> > pdl-general mailing list >> > [email protected] >> <javascript:_e(%7B%7D,'cvml','[email protected]');> >> > https://lists.sourceforge.net/lists/listinfo/pdl-general >> > >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> pdl-general mailing list >> [email protected] >> <javascript:_e(%7B%7D,'cvml','[email protected]');> >> https://lists.sourceforge.net/lists/listinfo/pdl-general >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > pdl-general mailing list > [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');> > https://lists.sourceforge.net/lists/listinfo/pdl-general > > >
------------------------------------------------------------------------------
_______________________________________________ pdl-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pdl-general
