if you have:
for(d1s - d1e)
for(d2s - d2e)
for(d3s - d3e)
...
for(dns - dne)

that means you actually execute the whole thing M=(d1e - d1s)*(d2e - d2s)*(d3e - d3s)*...*(dne - dns) times

So that means you can make a single loop 1..M and now you're left with the problem of extracting from the counter all the n counters you had initially.

If all the intervals you considered initially were equal(let's say the interval was I long) you could just write the new counter in base I and you get the initial indexes,but otherwise...it would probably be a bit more complicated.

You probably should convince yourself if the overhead in additional calculations is worth the effort. Good luck :)


In reply to Re: faster way for multiple foreach loops by spx2
in thread faster way for multiple foreach loops by michbach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.