1. I need the speed
- Posted by "Lucius L. Hilley III" <luciuslhilleyiii at JUNO.COM> Mar 17, 1997
- 1098 views
I need the fastest method to attain the same result. bitbuffer = is a buffer that holds bits to be written to file. i = value from 0 to 7 i2 = value from 0 to 255 bitbuffer = bitbuffer & int_to_bits(i, 3) & int_to_bits(i2, i + 1) That line is called very often. It is also the first call to bitbuffer so I have to prime it with bitbuffer = {} As of now the length of bitbuffer ranges from 0 to 18. The length of bitbuffer changes constantly. I have devised a method of solid length bitbuffer with a bitbuffer pointer called bp. I don't have the bitbuffer accumulating over 18 values as of know but I wonder if that would make a difference in speed? I use a while loop like the one below to write the bitbuffer out. while length(bitbuffer) > 7 do puts(file2, bits_to_int(bitbuffer[1..8]) bitbuffer = bitbuffer[9..length(bitbuffer)] end while Does anyone have a much better solution. My changes so far have changed the speed of a specified files proccessing from 1100 seconds to 957 seconds OR 18 min. 20 sec. to 15 min. 57 sec. 18:20 to 15:57 A little over a 2 minute speed increase but still way to slow. I don't want to wait 15 to 20 minutes for a 1.3 meg file being proccessed. PLEASE Help. :) --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 64K. -- I can Decode both UU and Base64 format.
2. I need the speed
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Mar 17, 1997
- 1061 views
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
3. Re: I need the speed
- Posted by "Cuny, David" <ATB.DCUNY at HW1.CAHWNET.GOV> Mar 17, 1997
- 1053 views
Using a pointer to an array, rather than concatonation was my first thought as well. You could try allocating some low memory and poking it directly there instead; that might trim off another .05%. :) Jacques has some file routines that write directly to disk, using BIOS calls. These might save you a little more time. Finally, there might be some small increase if you saved the whole 1.3 meg file buffer, and then wrote it all out to disk at once. I'm assuming that there might be some accumulated delays in separated disk seeks that might be avoided through a single write. Of course, even if that were true, it may not offset the time it takes Euphoria to build the structure, although I always assume that hardware is *much* slower than software, though. Good luck! -- David Cuny
4. Re: I need the speed
- Posted by "Lucius L. Hilley III" <luciuslhilleyiii at JUNO.COM> Mar 18, 1997
- 1082 views
On Mon, 17 Mar 1997 13:58:20 -0500 Robert Craig <robert_craig at COMPUSERVE.COM> writes: RC: ---------------------- Information from the mail header RC: If you want more speed I would recommend avoiding RC: int_to_bits() and bits_to_int() in favor of a solution RC: that uses the new and_bits(), or_bits() etc. routines in v1.5. Agreed !!! BUT I went over the code thoroughly and I just don't get it. RC: bitbuffer = and_bits(bitbuffer, i) RC: bitbuffer = or_bits(bitbuffer, i2 * SHIFT3) RC: bitbufferlen = bitbufferlen + 3 + i + 1 Okay, I see that you aren't converting bits into integers. And you appear to handling the bits directly. This will save space, AND most likely time. bitbuffer is called repeatedly. Some times it will be empty. Some times it will contain remaing bits from last call. I don't see how you this code is keeping those bits and then adding to the end of them, the additional bits of information. RC: while bitbufferlen > 7 do RC: -- puts(file2, bits_to_int(bitbuffer[1..8]) RC: puts(file2, bitbuffer) -- low-order 8 bits will be written to file RC: RC: -- bitbuffer = bitbuffer[9..length(bitbuffer)] RC: bitbuffer = floor(bitbuffer / SHIFT8) -- shift right 8 bits RC: bitbufferlen = bitbufferlen - 8 RC: end while I see that bitbufferlen is being used as a pointer to tell me how many bits are stored in bitbuffer. I understand that only the lower 8 bits are written to file as a byte, And I see how this code is then removing that byte written from the bitbuffer. Please clarify how the remaing bits in bitbuffer will not be lost and how the bits to be added are being stored into bitbuffer. I can see how those bits are being written and removed but I just seem to be missing how they are being put into bitbuffer. I can easily see how bitbufferlen is keeping track of how many bits are in bitbuffer. Thanks in advance. --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 64K. -- I can Decode both UU and Base64 format.
5. Re: I need the speed
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Mar 18, 1997
- 1111 views
- Last edited Mar 19, 1997
Lucius L. Hilley III writes: > Please clarify how the remaining bits in bitbuffer will not be lost > and how the bits to be added are being stored into bitbuffer. I hope the following will be a bit clearer and more accurate. Warning: I've checked the syntax, but I haven't actually run or tested the following code. ================================================================= constant SHIFT8 = power(2, 8) atom bitbuffer -- always >= 0, can hold about 30 bits bitbuffer = 0 integer bitbufferlen -- number of bits currently in the buffer bitbufferlen = 0 integer fn fn = open("datafile", "wb") -- remember to open for binary write procedure add_bits(integer value, integer len) -- Add a value to the buffer. Value is len bits long and >= 0. -- len is 0 to 7. -- store len in buffer: len = len * power(2, bitbufferlen) -- shift left by bitbufferlen bits bitbuffer = or_bits(bitbuffer, len) -- OR it into buffer bitbufferlen = bitbufferlen + 3 -- store value in buffer: value = value * power(2, bitbufferlen) -- shift left bitbuffer = or_bits(bitbuffer, value) bitbufferlen = bitbufferlen + len end procedure procedure write_bits() -- Write a byte from the buffer to the file. -- The low order 8 bits are removed. puts(fn, bitbuffer) -- only low-order 8 bits are written bitbuffer = floor(bitbuffer / SHIFT8) bitbufferlen = bitbufferlen - 8 end procedure ======================================= Regards, Rob Craig Rapid Deployment Software