Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Slowness when inserting into pre-extended array

by sgifford (Prior)
on Jul 20, 2003 at 01:18 UTC ( [id://275993]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Slowness when inserting into pre-extended array

You could verify what part of your code is being slow either by using the Time::HiRes module to time different parts of your code:
use Time::HiRes qw(time); use vars qw($then); sub timepart { my($partname)=@_; my $now = time; if ($partname) { $time{$partname} += $now - $then; } $then = $now; } timepart(); foreach my $line (@FILE) { timepart('loop'); if (($dot % 1000) == 0) { print STDERR "."; } timepart('mod'); $line=~/^(\S*) [0-9.]* (.*)$/o; my ($class, $feature_vector) = ($1, $2); timepart('regex'); my %case; $case{'class'}=$class; timepart('createcase'); foreach my $feature (split /\s+/, $feature_vector) { $case{'fv'}{$feature}=1; } timepart('feature'); push @cases, \%case; timepart('pushcase'); $dot++; } print "\n"; while(my($k,$v)=each(%time)) { printf "%10s: %10.6f\n",$k,$v; }
or by reducing your code to a very small amount and seeing if it's still slow:
for $i in (1..2_000_000) { my %case; push(@r,\%case); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://275993]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.