From: "meinrad.recheis" Date: 2003-05-12T14:58:53+09:00 Subject: Re: efficiency advice needed On Mon, 12 May 2003 08:31:58 +0900, Ryan Pavlik wrote: > On Mon, 12 May 2003 06:56:27 +0900 > "meinrad.recheis" wrote: > > >> data = '' >> (width*height).times{ >> data += rgb.read( 3) + alpha.read( 1) >> } >> >> i think alternately reading some bytes is slowing down alot. but also >> loops operating on strings are >> slow, i think. i know some solutions, but i don t know which one to use. >> are there any suggestions how to do this most efficiently in ruby? > > > Read everything into an array or string and go from there... I don't > thing String operations are particularly slow, but I could be wrong. > You _might_ read in the entire file as a string (or a given chunk, for > scaleability's sake), String#unpack it, and go from there, but that > sounds like a waste of memory for something like this. > unpacking makes no sence for me. i lately thought of inserting the alpha characters into the rgb string using String#insert from back to front, so i don t need to worry about changing indices (due to insertion) and i can Striong#chop! off the used alpha bytes. there are several other ways to do it, but i allways want to keep code short and easy. thanks for comments, mr. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/