Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am using Parallel::ForkManager to test a webservice. The most important piece of information I need is how long each fork took to process the request. Here is a sample of my code

#!/usr/bin/perl use warnings; use strict; use File::Basename; use diagnostics; use Parallel::ForkManager qw( ); use Time::HiRes qw( time ); my $max_processes = 5; my $home = '/vagrant'; my $url = ''; my @files = `ls $home/*.zip`; my $pm = Parallel::ForkManager->new($max_processes); foreach my $zip (@files){ chomp $zip; my $start = time(); my $pid = $pm->start and next; my $filename = `unzip -l $zip | awk '{print \$4}' | grep -P '.*-\\ +d+\\.xml'`; chomp $filename; my $header = "curl -s --header 'Content-Type: application/zip' --d +ata-binary '@" . $zip . "' '". $url . $filename . '&media' . "=xml'"; my @response = `$header`; foreach my $line (@response){ chomp $line; if ($line =~ m/\<ref href\=\"(.*-\d+\.xml)\"\/\>\<\/entry\>/){ print "XBRL Name -- $1\nExpected Filename -- $filename\n"; last; } } my $end = time(); print "Runtime --- "; printf("%.2f\n", $end - $start); print "\n\n"; $pm->finish; } $pm->wait_all_children;

The output of the runtime is incorrect as it seems like the start time is not processed for each item in my array. There must be a better way to do it but damned if I know. Your help would be greatly appreciated


In reply to Finding the run time of a Fork process by edimusrex

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2021-10-28 14:28 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (96 votes). Check out past polls.