Question: How to partition a list fast?

Hello

I have a list with a large number of elements and I need to partition it in chunks of a specific size.  Here is my attempt

listpart := proc(cond::list,nchunk::nonnegint:=1000)
if numelems(cond) < nchunk then
	newcond:=[cond]:
else
	ss:=[`$`(1..numelems(cond))]:
	sss:=map(`mod`,ss,nchunk):
	ind:=[ListTools:-SearchAll(0,sss)]:
	ind:=[0,op(ind),ifelse(ss[numelems(ss)]=ind[numelems(ind)],[],ss[numelems(ss)])]:
	newcond:=[Threads:-Seq(cond[(ind[j]+1)..ind[j+1]],j=1..(numelems(ind)-1))];
end if:
return(newcond):
end proc:

It does not run as fast as I thought.  I am not even sure if Threads:-Seq could be used in this case.  Please tell me what I am doing wrong and how I can modify the code to get a faster response.  

Many thanks

Ed

 

Please Wait...