in reply to Re^12: list of unique strings, also eliminating matching substrings
in thread list of unique strings, also eliminating matching substrings
ATM I can't see any influence of string allocation.
Try it with 200,000 strings where half are to be excluded, then you'll see the affects of allocating and copying 300 bytes; then allocating and copying 600 bytes & freeing 600; then allocating and copying 900 bytes & freeing 900; ... 99,995 allocs/copies/frees omitted ...; then allocating copying 29,999,700 bytes & freeing 29.9997MB; then allocating and copying 30,000,000 bytes & freeing 30MB.
Each time you do $longest .= "\n" . $x; perl has allocate a new chuck of memory big enough to accommodate $longest + $x; then copy those two into the newly allocated space, then free both the originals. And as each freed allocation is not big enough to accommodate the next iteration of append, each new allocation (once you get past trivial amounts) requires Perl to go to the OS for a new chunk of virtual memory. And that gets very costly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^14: list of unique strings, also eliminating matching substrings
by LanX (Saint) on Jun 03, 2011 at 15:25 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2011 at 15:53 UTC | |
by LanX (Saint) on Jun 03, 2011 at 16:05 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2011 at 16:31 UTC | |
by LanX (Saint) on Jun 03, 2011 at 17:03 UTC | |
|