This is a good example of what people mean when they say, "That solution doesn't scale well.

The problem is that the algorithm you've devised to partition the data by range runs in something like O(n^3) time (or worse), which means that as your dataset grows by n elements, the work being done grows by at least n^3 (again, it might be worse in final analysis). You have a construct of four 'for' loops nested, and then two 'for' loops nested later.

As the dataset grows, you go from a relatively small number of iterations, to billions of iterations, rather quickly, and the program appears to grind to a halt -- in reality it's working really really hard.

Couldn't you predeclare your ranges, and then in a single loop test which ranges each line of data fits into?

Your next problem is that you're slurping the entire file. That means that you must hold the entire 22mb file in memory. Plus, the array you're generating must fit in memory too. You're probably getting to a point where your operating system cries uncle and starts using hard-disk swap space. With a lot of swapfile churning, you also get dreadfully slow performance. It would work a lot better if you could read your data in line by line and process it, one line at a time.


Dave


In reply to Re: inefficient code? works on small files ok but not larger ones by davido
in thread inefficient code? works on small files ok but not larger ones by Anonymous Monk

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.