Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Perl script performance help

by GotToBTru (Prior)
on Jul 05, 2016 at 12:48 UTC ( [id://1167234]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl script performance help
in thread Perl script performance help

He was suggesting you don't have to do the reverse 7 times. I don't think that's true.

He also suggested you test the size of the variable and don't perform the substr() commands that will just return undef.

my $start_run = time(); use strict; use Benchmark; use warnings; my @array = (1..1000000000); foreach (@array) { for(my $i=1; $i<length($_);$i++) { if ($_==reverse(substr($_, 0, $i) * substr($_, $i))) { print $_."\n" ;} } } my $end_run = time(); my $run_time = $end_run - $start_run; print "Time taken: ".$run_time." sec\n";
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Replies are listed 'Best First'.
Re^4: Perl script performance help
by G0G0 (Initiate) on Jul 05, 2016 at 13:44 UTC
    now i understand, thanks for the help but the funny thing is that it take more time than before

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1167234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found