I need the speed

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lucius L. Hilley III writes:

> I don't want to wait 15 to 20 minutes for a 1.3 meg file being
> proccessed.

If you want more speed I would recommend avoiding
int_to_bits() and bits_to_int() in favor of a solution
that uses the new and_bits(), or_bits() etc. routines in v1.5.

Below I have sketched an alternative way of performing
your bit-buffer manipulations using the new routines.
There are no left/right shift operators in Euphoria so
you have to use multiply and divide by powers of 2.
Note that puts() automatically writes the lower 8-bits of
each value to a byte in the file. The code below doesn't
do anything interesting, it just shows an alternative.

==================================================================
-- bitbuffer = is a buffer that holds bits to be written to file.
-- i = value from 0 to 7
-- i2 = value from 0 to 255

constant SHIFT3 = power(2, 3),
         SHIFT8 = power(2, 8)

integer i, i2, bitbufferlen, file2
i = 7
i2 = 255
file2 = 1

atom bitbuffer
bitbuffer = 0
bitbufferlen = 0

-- bitbuffer = bitbuffer & int_to_bits(i, 3) & int_to_bits(i2, i + 1)
bitbuffer = and_bits(bitbuffer, i)
bitbuffer = or_bits(bitbuffer, i2 * SHIFT3)
bitbufferlen = bitbufferlen + 3 + i + 1

-- while length(bitbuffer) > 7 do
while bitbufferlen > 7 do
     -- puts(file2, bits_to_int(bitbuffer[1..8])
     puts(file2, bitbuffer) -- low-order 8 bits will be written to file

     -- bitbuffer = bitbuffer[9..length(bitbuffer)]
     bitbuffer = floor(bitbuffer / SHIFT8) -- shift right 8 bits
     bitbufferlen = bitbufferlen - 8
end while

======================================

Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu