Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Grep is not the performance issue here. Perl grep is actually way cool and super fast.

The performance issue here appears to me to be that you are iterating in an outer loop over each thing in @ServiceCheckList AND THEN iterating again over every element in @ServicesOnMachine for every thing in @ServiceCheckList in an inner loop. So this takes CheckList * OnMachine iterations.

My code takes one pass through each item in CheckList and OnMachine to build the hash. Then one more time through essentially both to generate the intersection. That is (CheckList+OnMachine)*2 operations, less than (CheckList * OnMachine) operations.

On another point, I personally prefer the grep BLOCK LIST syntax - for me, it is easier to read and understand.
@output = grep{ TRUE OR FALSE }@input;

If what is inside the grep BLOCK evaluates to "TRUE", pass the input to the output on the left. What is inside the grep BLOCK can be arbitrarily complex, but it all comes down to essentially "true" or "false". Perl grep could have been called "filter" because a subset of @input appears on the @output. A regex can be within the BLOCK, @output = grep{/^abc/}@input passes things that begin with "abc" from the input to the output because the regex evaluates to "true" in that case.


In reply to Re^2: Comparing two arrays... by Marshall
in thread Comparing two arrays... by austin43

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 contemplating the Monastery: (5)
As of 2024-04-24 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found