Roey, I think you're right on here. The default zeroes/zeros uses the PP threading engine to loop over the elements, well, elementwise - ie byte by byte. The string assignment uses an optimized memory copy that is part of Perl and almost certainly does things word by word. On a 64 bit machine, that means zeroes does 8x more work than it has to in this specific case.
This is a good idea for a fix. There are probably more pressing things that need to be finished first (I'm "only" 9 months behind on getting the core-cleanup branch clang-clean, for example), but it's a localized patch to zeroes and ones if someone wants to make it. Cheers, Craig On Sep 18, 2014, at 5:22 AM, Roey Almog (Infoneto Ltd) <al...@infoneto.co.il> wrote: > Hi, > > I am a bit new to PDL so if the answer is obvious I have missed it some how... > > I have around 1 million vectors of about 1 million elements long each element > is one byte in size > > The information is streamed in, one vector at a time with input data - the > data itself is not read from a file its real life information collected so > every time I run the program I get something else. > > I found that initializing the vectors with zeros takes long time, seems that > zeros iterates on all the cells settings them to zero > > so I created any empty pdl with zeros and each time I need to create a PDL I > use > this methos > > # this is done once > my $pdl_template = zeros(byte, $size); > my $buffer_template = $pdl_template->get_dataref; > > > # now when getting the information > my $pdl = PDL->new_from_specification(byte, $size); > my $ptr_buffer = $pdl ->get_dataref; > $$ptr_buffer = ${$buffer_template}; > $pdl->upd_data; > > This is about 7 times faster than zeros, however it would be better if zeros > (and also ones) had some optimization to clear an empty vector even faster > using c's memset function when applicable (bytes. shorts integer etc.) > > As this seems very useful I wonder if I missed something ? > > Thanks > Roey > _______________________________________________ > Perldl mailing list > Perldl@jach.hawaii.edu > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl _______________________________________________ Perldl mailing list Perldl@jach.hawaii.edu http://mailman.jach.hawaii.edu/mailman/listinfo/perldl