Re: map vs append

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

I just have to report, if you aren't using maps, you're probably missing out on a ton of speed.

I have a program that loads the contents of over 4600 files and creates a cache file of their contents. Before, this was taking upwards of 30 seconds. Not a big deal in the whole scheme of things, but idle fingers cost money.

After, now using maps instead of sequences, it takes less than 2 seconds to complete.

I suspect the main speed-up has been the change from using a single sequence to hold the file cache to using multiple sequences.

When you append to a sequence, Euphoria allocates enough space to hold all the existing items in the sequence plus the new item(s), then copies all the existing items and new items to the new space, then removes the old sequence. As a sequence grows, this can have quite a large overhead. In general, avoid appending to large sequences.

A map's internal structure has many sequences, nearly all of them are very sort ones, so appending to these is usually a lot faster.

BTW, if notice you use this type of construct ...

   if map:has( themap, key ) then 
       data = map:get( themap, key )  

It might be faster if you use ...

   data = map:get( themap, key, badvalue )  
   if not equal(data, badvalue) then  
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu