CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Time elapsed issue

 



Chaoui005
Novice

May 18, 2016, 1:43 AM

Post #1 of 6 (1852 views)
Time elapsed issue Can't Post

Hi everybody ! I appeal to your legendary wisdom. I have this following issue. I created a timer to get time elapsed between beginning of my tests and the end of them.
But depending where i put my "end time" line, i have a different output in my Shell.

I did this code :

Code
use Modern::Perl; 
use strict;
use warnings;
package MyTestingSuite;

use parent 'Test::Class';
use Test::Selenium::Remote::Driver;
use Test::More;
use POSIX qw(strftime);



my $start = time();
cprint "Started at ", (strftime '%A %d %B %Y %H:%M:%S',localtime($start)), "\n";


sub startup : Test( startup => no_plan ) {
my $self = shift;
$self->{browsers} = [('firefox', 'internet explorer', 'chrome', 'phantomjs')];
}

# WHEN I PUT MY END TIME HERE:

my $end = time();

cprint "Ended at ", (strftime '%A %d %B %Y %H:%M:%S', localtime($end)),"\n";

cprintf "Total run time:", $end-$start, " seconds\n";
printf ("%02d:%02d:%02d\n",(gmtime($end-$start))[2,1,0]);

I HAVE THIS OUTPUT IN MY SHELL:
Started at 2016-05-17-16-55-00
1..0
Ended at 2016-05-17-16-57-04
Total run time:0 seconds
.....ALL MY TESTS .....

sub Login_test : Tests {


$driver->quit();
}

}

sub Logout_test : Tests {


$driver->quit();
}

}

sub Navigation_test : Tests {


$driver->quit();
}
# WHEN I PUT MY END TIME HERE:

my $end = time();

cprint "Ended at ", (strftime '%A %d %B %Y %H:%M:%S', localtime($end)),"\n";

cprintf "Total run time:", $end-$start, " seconds\n";
printf ("%02d:%02d:%02d\n",(gmtime($end-$start))[2,1,0]);

I HAVE THIS OUTPUT IN MY SHELL:
Started at 2016-05-17-16-57-04
1..0
....ALL MY TESTS .....

Ended at 2016-05-17-17-03-04
Total run time:360 seconds
}



So in second position, inside Sub, it works fine , because i have all my tests inside my timer and so i can have elapsed time. But problem is that i can have random sub in my test . Also even if i place my end timer in the last Sub it can cut my timer inside my tests and not at the end of end.

I think about a conditionnal loop to get all my sub when they finish all to call my end time but i don't know how .
How can i do?
Many Thanks !

PS: I posted this in Perlmonks but i didn't have return. Thanks again


Laurent_R
Veteran / Moderator

May 18, 2016, 10:11 AM

Post #2 of 6 (1836 views)
Re: [Chaoui005] Time elapsed issue [In reply to] Can't Post

The code you are showing doesn't appear to be doing anything. None of the subroutines you define is called.

So it appears that you don't show your real code.

Also some of the output does not make sense:


Code
Started at 2016-05-17-16-55-00  
1..0
Ended at 2016-05-17-16-57-04
Total run time:0 seconds

It seems that the program ran for a bit more than 2 minutes and you print 0 second. Also the output is one line less that the number of print statements.

Please show separately the code and the output, show the real code and show the real output. Too many things seem inconsistent in what you posted.


Chaoui005
Novice

May 19, 2016, 7:26 AM

Post #3 of 6 (1825 views)
Re: [Laurent_R] Time elapsed issue [In reply to] Can't Post

Yes Laurent. I know. Because i deleted all the code inside my sub. I wrote "sub" just to present my code.

But problem is just concerning my timer part of code. I resolved now the problem.

Many thanks for your reply colleague !


bulrush
User

May 26, 2016, 7:38 AM

Post #4 of 6 (1795 views)
Re: [Chaoui005] Time elapsed issue [In reply to] Can't Post

Look into the Benchmark module, it's pretty handy. http://search.cpan.org/~rjbs/perl-5.24.0/lib/Benchmark.pm
-----


Chaoui005
Novice

May 27, 2016, 12:27 AM

Post #5 of 6 (1789 views)
Re: [bulrush] Time elapsed issue [In reply to] Can't Post

I will. Thanks for reply


Chaoui005
Novice

May 27, 2016, 1:56 AM

Post #6 of 6 (1787 views)
Re: [bulrush] Time elapsed issue [In reply to] Can't Post

Yes ! Really, it's handy !

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives