in reply to Thread::Queue memory issue with nested maps but not foreach loops...
I would like to know why the nested maps produces the behavior?
First. Take threads and Thread::Queue out of the equation. They are innocent bystanders in the issue.
Using nested maps, this require 49MB and 11.4 seconds of cpu time to complete:
C:\test>perl -E"$c=0; map map( ++$c, 1..1e3 ), 1..1e3; say 'check mem' +;<>" check mem 49 MB
Whereas, this using nested for loops requires just 2 1/2 MB and 0.014 seconds of cpu:
C:\test>perl -E"$c=0; for( 1..1e3 ) { ++$c for 1..1e3 }; say 'check me +m';<>" check mem 2.5MB
For why,
(*)for will also build a list in some circumstances, but far less frequently.
It pays to know (some of) the internal details of your language.
(As an aside, filling Thread::Queues will huge numbers of items costs big in terms of memory and runtime. Better to limit how much you push into them at one time).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Thread::Queue memory issue with nested maps but not foreach loops...
by ikegami (Patriarch) on Mar 03, 2012 at 08:41 UTC | |
by BrowserUk (Patriarch) on Mar 03, 2012 at 09:13 UTC | |
by ikegami (Patriarch) on Mar 05, 2012 at 06:55 UTC | |
|
Re^2: Thread::Queue memory issue with nested maps but not foreach loops...
by Anonymous Monk on Mar 03, 2012 at 05:15 UTC | |
by BrowserUk (Patriarch) on Mar 03, 2012 at 05:20 UTC | |
by ikegami (Patriarch) on Mar 03, 2012 at 08:40 UTC | |
by BrowserUk (Patriarch) on Mar 03, 2012 at 09:41 UTC |