Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Why is const x const not a const?

by The Perlman (Scribe)
on Jan 23, 2012 at 00:59 UTC ( [id://949297]=note: print w/replies, xml ) Need Help??


in reply to Re: Why is const x const not a const?
in thread Why is const x const not a const?

Hmm...

seems like I misunderstood the question, but maybe constant-folding something like "a" x 100000 is not always efficient?

Replies are listed 'Best First'.
Re^3: Why is const x const not a const?
by ikegami (Patriarch) on Jan 23, 2012 at 09:37 UTC

    Then why does «sprintf '%-100000s', 'a'» create a string of 100,000 characters at compile-time like «"a" x 100_000» currently does at run-time.

    And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

    If something could fold into something that's considered too large, that particular folding should be prevented, not all foldings of that operator.

      And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

      It does? How can you tell?

      Neither B::Deparse nor B::Concise seem to indicate that, nor the compile time memory consumption.

        It shows up as const AV in the opcode tree.

        You can prove the list is flattened once using

        for (1..2) { for ((), 4..8) { say $_++; } }

        Update: Added missing parens.

      And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

      Really? Can you demonstrate that?

      Because I see no evidence for it:

      c:\test>perl -le"++$n for 1..1e2; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 7500 Console 1 5 +,716 K c:\test>perl -le"++$n for 1..1e3; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 3676 Console 1 5 +,712 K c:\test>perl -le"++$n for 1..1e4; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 6048 Console 1 5 +,732 K c:\test>perl -le"++$n for 1..1e5; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 5648 Console 1 5 +,720 K c:\test>perl -le"++$n for 1..1e6; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 8620 Console 1 5 +,736 K

      Whilst the memory usage varies a little, it sometime goes down a few k when the notional size of this array increases by an order of magnitude?

      Conversely, if you explicitly create an array of that size, the memory requirement increases by 100MB as expected:

      c:\test>perl -le"@a = 1 .. 1e6; system qq[tasklist /nh /fi \"pid eq $$ +\"] " perl.exe 2664 Console 1 109 +,576 K

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        > Because I see no evidence for it:

        Not surprising

        for (START .. STOP) { }

        is magically optimized into an iterator to avoid building the list.

        But if you try

        for (reverse START .. STOP) { }

        instead, you will see the memory consumption, because that optimization is (unfortunately) missing here.

        Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://949297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found