in reply to My Binary Search Perl code takes forever
blokhead's analysis sounds true. When dealing with millions of values, Perl uses up all available memory.
Since you're only using integers, one method to reduce memory usage considerably is to use a string of packed integers. Tie::IntegerArray makes this transparent for you. (It's suppose to, at least. Untested.) Use it in conjunction with blokhead's change to use a reference.
my @integer_array; tie @integer_array, 'Tie::IntegerArray', bits => 32, signed => 1, size => 1_000_000; # Pre-allocate this many
By the way, why do you switch from a binary search to a linear search to find the beginning of a match?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: My Binary Search Perl code takes forever
by Anonymous Monk on Dec 15, 2007 at 19:00 UTC | |
by ikegami (Patriarch) on Dec 15, 2007 at 22:23 UTC |