Re: Constructing sequences

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

Gordon Webster wrote:
> Aaaaaaaaaaah! Thanks Matt
> 
> It's all the individual memory allocations that take the time on the
> 'append' operation. Using your method of pre-allocating memory in blocks,
> my 40 second sequence build comes down to 0.05s - an 800x speedup!
> 
> BTW: just for fun, when I compiled this, the time was too small to be
> displayed by the time() function for 100,000 records added.
> 
> I will allocate and expand my sequences in blocks from now on.

That sounds like a good solution, however
I did a test on my Pentium-4 1.8GHz machine...

integer fn
object line
sequence buffer

-- create file
fn = open("bigfile.txt", "wb")
for i = 1 to 100000 do
    puts(fn, 'A' + rand(repeat(100, 19 + rand(11))))
    puts(fn, '\n')
end for
close(fn) -- file is about 2.5Mb

-- read file
fn = open("bigfile.txt", "rb") -- 100,000 lines of 20 to 30 random chars

atom t
t = time()

buffer = {}
while 1 do
    line = gets(fn)
    if atom(line) then
	exit
    end if
    buffer = append(buffer, line)
end while

close(fn)

? time() - t -- 4.06 seconds, 1.8GHz Pentium-4

? length(buffer) -- 100,000


With 2.5, ex.exe took 4.06 seconds. 
With 2.4, ex.exe took 4.34 seconds.

Maybe your machine is much slower, or maybe you
were not appending to a simple variable, like "buffer",
but rather to a subscripted variable. The latter case
is not optimized as well.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu