in reply to Why it takes so much time here?

You've run out of memory and resorted to using virtual memory.

100,000,000 scalars x 16 bytes = 1.5 GB just in data. Then there's the overhead of 100,000,000 memory blocks, and there's possibly waste resulting from alignment issue.

Replies are listed 'Best First'.
Re^2: Why it takes so much time here?
by PerlOnTheWay (Monk) on Dec 28, 2011 at 03:24 UTC

    My system has 7GB memory,how can it run out of memory for 1.5GB?

    [anony@dev-test test]$ free -g total used free shared buffers cac +hed Mem: 7 1 6 0 0 + 0 -/+ buffers/cache: 1 6 Swap: 1 1 0
      My system has 7GB ... (6GB free)

      On my system, creating a list of 10_000_000 scalars on Perl's stack already takes roughly 700MB. So, as you have 10 times as many, 7GB is pretty close...

      Try this

      $ perl -MList::MoreUtils -e'any {<>} 1..10_000_000'

      and check its memory usage with top or ps (abort with ^C).

      Ok, what about pure CPU speed limitations?

      15/100,000,000 s per iteration
      = 0.00000015 s per iteration
      = 150 ns per iteration

      Is that unreasonable?

        I printed the time before and after the iteration, the result is both 1325041218:

        print time . "\n"; my @a = any {$_== 92} 1..100000000; print "\n"; print time;

        So the time is not taken by the iteration..