Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Nice meditation!

After a bit of review I realized that the problem was due to the way I was implementing the cache lookup. The process was essentially this: produce the union of four queries each of which returned a variable number of two field records, (the first number being a telephone prefix, and the second being an ID that represented its pricing model) then join that data together to form a string key that could be used in a hash lookup to determine if the data was already in the cache.

Some other ideas:

  • use the queries themselves as the key into the cache instead of the results
  • since most of the data is sorted already, instead of just pushing onto the end, insert them at the correct place
  • and, inspired by a recent QOTW ... it shouldn't matter that the data are sorted asciibetically, just that they're sorted the same way each time. So you can do something like this:
    use List::Util qw(shuffle); my $alphabet = join '', shuffle 'a'..'z'; # do this only once and sav +e it to a file for later reading my $t; @union = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { eval "(\$t = lc \$_) =~ tr/$alphabet/a-z/"; [ $t, $_ ] +} @union;
    Not sure if there's a win there or not, but it's interesting anyway :)


In reply to Re: Bitten by the worst case (or why it pays to know whats inside the black box) by duff
in thread Bitten by the worst case (or why it pays to know whats inside the black box) by demerphq

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found