in reply to Saving an array to a disk file
Well, what have you tried as far as benchmarking is concerned? I actually would expect:
to be about as fast as it gets (i.e., not chewing up stupid amounts of memory if that array really is big, while still allowing your cache to save time). But I haven't benchmarked it, and computers can do really strange things that us humans don't expect.{ my $old = select $fh; local $\="\n"; print for @very_big_redundant_array; select $old; }
That said, even faster is probably to not save it, but to uniq-sort it in memory:
By bypassing the disk, you can get huge improvements in speed. If you run out of memory, this will still swap to disk, but that shouldn't be slower than your method. Only if you run out of address space will you actually have problems (which could be 1.5GB, 2GB, 3.5GB, 3.75GB, or some number of TB or something, depending on OS and architecture) that using the disk manually would prevent.my @very_big_sorted_unique_array = do { my %seen; $seen{$_} = 1 for @very_big_redundant_array; sort keys %seen; };
Of course, if your intention is to have a reboot in the middle somewhere, then persistant storage is important - don't get me wrong, saving a huge amount of data as quickly as possible is still a worthwhile question. But I'm not sure it is necessarily an important question for you without knowing that you need to load the data in another process.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Saving an array to a disk file
by Anonymous Monk on May 26, 2006 at 05:18 UTC | |
by Tanktalus (Canon) on May 26, 2006 at 12:57 UTC | |
by dsheroh (Monsignor) on May 26, 2006 at 16:32 UTC |