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 = 'http://xxx.xxx.xxx.xxx/rest/xbrl/validation?file='; 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

Thanks!


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

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.