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: Intermediate:
Time in seconds

 



ab
Novice

Nov 3, 2009, 6:46 AM

Post #1 of 4 (2114 views)
Time in seconds Can't Post

Hi all

i have a perl script that print out all prime numbers up to a chosen integer but i need a way to find out how long it took to run

i have used the "print time - $^T;" option but this only does seconds, is there a way so it can do more than just seconds , say micro seconds, below is my code

Code
#!/usr/bin/perl 
use strict ;
my @list = 1..10000;
foreach $a (@list) {
my@total=();
foreach $b(@list) {
if ((int($a/$b)==($a/$b))) {
push @total, $b;
}
}
print "$a is prime\n" if ($#total == 1);

}
print time - $^T;



FishMonger
Veteran / Moderator

Nov 3, 2009, 6:49 AM

Post #2 of 4 (2113 views)
Re: [ab] Time in seconds [In reply to] Can't Post

Time::HiRes
http://search.cpan.org/~jhi/Time-HiRes-1.9719/HiRes.pm


ab
Novice

Nov 3, 2009, 6:55 AM

Post #3 of 4 (2110 views)
Re: [FishMonger] Time in seconds [In reply to] Can't Post

sorry i am sure i am being a complete numpty but how was i used that with my code

thanks


FishMonger
Veteran / Moderator

Nov 3, 2009, 7:19 AM

Post #4 of 4 (2107 views)
Re: [ab] Time in seconds [In reply to] Can't Post

First, don't use $a or $b. Those are 2 of Perl's special built-in global vars that are used in the sort function.

Var names should describe (or give a hint) what data the var holds.

Have you read the documentation for the module? It provides several examples of its usage.

This is clearly a homework assignment, so I can't/won't provide the complete solution. But, if you give it a try and get stuck, post the updated code that you're testing with a specific question on the part that you can't figure out, I'll give you a little more guidance.

 
 


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

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