I guess the basic answer is that it is horribly inefficient in both memory space and CPU time.
(1)x$_ builds a list of $_-many copies of the number 1. That involves allocating $_-many (which could be hundreds of thousands) SV structs (what Perl stores scalar values in) and an array to hold pointers to all of them. Then the remaining values from @counts are moved "up" to make room so this array of pointers can be copied into place. Repeat this for each count.
Then map checks the size of the resulting huge list and returns it, throwing away the list which results in at least $sum-many calls to free() which each have to adjust memory management buffer pointers, etc.
But at least the code looks nice.
- tye (but my friends call me "Tye")In reply to (tye)Re2: sum of counts
by tye
in thread sum of counts
by tye
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |