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??

As the old joke goes: if I were setting out to get there, I wouldn't be starting from here!

Presumably you do not magically start out with these thousands of Set::IntSpan objects. You must be building them up from the log file(s)?

If so, it would be far more efficient to build up your required final representation, at the same time, (or in place of), as you are iterating the log and generating those objects. The logic is far simpler and falls out naturally from the ordered nature of the log:

my @timeSlots; my $concurrent = 0; my $lastTimeSlot = 0; while( <$log> ) { my( $time, $type ) = m[(...).+(Start|End)]; ++$concurrent if $type eq 'Start'; --$concurrent if $type eq 'End'; my $timeSlot = timeToTimeslot( $time ); push @timeSlots, ( $concurrent ) x ( $timeSlot - $lastTimeSlot ); $lastTimeSlot = $timeSlot; ## Do stuff to build your intspan objects ... }

By the time you've iterated the logs and generated the IntSpan objects, you already have your array of concurrency counts per timeslot for free.


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.

In reply to Re: Efficient algorithm needed to split Set::IntSpan objects by BrowserUk
in thread Efficient algorithm needed to split Set::IntSpan objects by tim.bunce

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 taking refuge in the Monastery: (5)
As of 2024-04-19 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found