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

Re: Re: Question about benchmarking

by jryan (Vicar)
on Aug 18, 2001 at 00:27 UTC ( #105802=note: print w/replies, xml ) Need Help??

in reply to Re: Question about benchmarking
in thread Question about benchmarking

Thanks for that information about benchmarking, that is exactly what I needed. Btw, what I meant by "I don't trust it because it is too simple" is that it looked like too simple of a solution to what looked to be a complex problem, but really wasn't.

For those who still want to see the code, here it is (I've removed all of the stuff that doesn't have to do with the hierarchy part, to cut down on confusion):

#!/usr/bin/perl # *********************** # Name: # Author: Joe Ryan # Date Finished: August 10th, 2001 # Where Used: # Description: An extension to that lets the # user browse through the amherst website, showing the hits # per directory and per file. Note that the script # doesn't directly run off the weblog, but rather a text # file that is created after processing the weblog. open(DATA, 'pagehits.txt'); @mlines = <DATA>; close(DATA); $cutat = 2; # recursive function that prints the hierarchy sub print_hierarchy { my ($newlevelref, $newhitsref, $x, $stophere, $plvars, $temp, $tem +p1, $resume) = @_; my (@newlevel) = @$newlevelref; my (@newhits) = @$newhitsref; if ($x<=$cutlevelat) { print "<ul>\n"; $spaces = "<li>"; $spacesend = "</li>"; my ($y)=0; for ($y=0; $y < @newlevel; $y++) { my ($newleveltemp) = $newlevel[$y]; my ($newhitstemp) = $newhits[$y]; my ($temp2) = $temp.$newleveltemp; my ($temp3) = $temp1.$newleveltemp; my ($p_count) = ($newleveltemp =~ tr/\.//); if ($p_count < 1) {$temp2.="/"; $temp3.="/";} eval ("\$plvars1 = \$plvars\.\"&pathlevel".$x."=\$newlevel +temp\""); print "$spaces $newhitstemp&nbsp;<a href=\"$temp2\">$newle +veltemp</a>&nbsp;<a href=\"/cgi-bin/weblog/" +.($x+1)."$plvars1\">></a>&nbsp;<a href=\"/cgi-bin/weblog/ +?addwatch=$temp3&addhits=$newhitstemp&cutlevelat=".($x+1)."$plvars\"> ++</a>$spacesend\n" unless ($newleveltemp =~ /\./ || $newleveltemp eq +""); if ($y == $stophere) { eval ("print_hierarchy(\\\@newlevel".($x).", \\\@newhi +ts".($x).", ".($x+1).", \$stophere".($x+1).", \$plvars1, \$temp2, \$t +emp3, 1)"); } } print "$spaces<b>--------------</b>$spacesend\n"; for ($y=0; $y < @newlevel; $y++) { my($newleveltemp) = $newlevel[$y]; my($newhitstemp) = $newhits[$y]; my($temp2) = $temp.$newleveltemp; my($temp3) = $temp1.$newleveltemp; eval ("\$plvars1 = \$plvars\.\"&pathlevel1=\$newleveltemp\ +""); my($p_count) = ($newleveltemp =~ tr/\.//); if ($p_count < 1) {$temp2.="/"; $temp3.="/";} print "$spaces $newhitstemp <a href=\"$temp2\">$newlevelte +mp</a>"."&nbsp;<a href=\"/cgi-bin/weblog/$temp3 +&addhits=$newhitstemp&cutlevelat=0$plvars\">+</a>\n" if ($newleveltem +p =~ /\./ && $newleveltemp ne ""); } print "</ul>\n"; } else { return 1; } } use CGI; $query = CGI::new(); # $cutlevelat is how many levels out a directory is from the base $cutlevelat = $query->param("cutlevelat"); $cutlevelat=0 if (!$cutlevelat); for ($i=0; $i<$cutlevelat; $i++) { eval ("\$pathlevel".$i." = \$query->param(\"pathlevel".$i."\")"); } print "Content-type: text/html\n\n<html><head><title>Hierarchy View</t +itle></head><body bgcolor=\"#FFFFFF\">\n"; @mypath = (""); @myhits = (0); $y=0; $v=0; for ($i=0; $i<$cutlevelat; $i++) { eval("\$n".$i."=0"); } for($i=0; $i<@mlines; $i++) { @entry = split (' ', $mlines[$i]); @path = split (/\//, $entry[0]); $temp=""; $x=1; for (; $x<=$cutat;$x++) { $path1[$x-1]=$path[$x-1]; $temp.=$path[$x-1]; $temp.= "/"; } $breakcheck=1; for ($c=0; $c<$cutlevelat; $c++) { $breakcheck=1; eval("\$pathlevel=\$pathlevel".$c); if ($path[$#path1+$c] eq $pathlevel) { eval("\$meep=\@newlevel".$c); for($z=0; $z<$meep; $z++) { eval ("\$narf=\$newlevel".$c."[\$z]"); if ($path[$#path1+1+$c] eq $narf) { eval ("\$newhits".$c."[\$z]+=\$entry[1]"); $breakcheck=0; } } if ($breakcheck) { eval("\$newlevel".$c."[\$n".$c."] = \$path[\$\#path1+1 ++".$c."]"); eval("\$newhits".$c."[\$n".$c."] = \$entry[1]"); eval("\$n".$c."++"); } } } $entry[0]=$temp; $breakcheck=1; for($x=0; $x<@mypath; $x++) { if ($entry[0] eq $mypath[$x]) { $myhits[$x]+=$entry[1]; $breakcheck=0; } } if ($breakcheck) { $mypath[$t]=$entry[0]; $myhits[$t]=$entry[1]; $t++; } } @indices = (0 .. $#myhits); @sorted_indices = sort {$myhits[$b] <=> $myhits[$a]} @indices; @myhits = @myhits[@sorted_indices]; @mypath = @mypath[@sorted_indices]; for ($i=0; $i<$cutlevelat; $i++) { eval("\@indices = (0 .. \$\#newhits".$i.")"); eval("\@sorted_indices = sort {\$newhits".$i."[\$b] <=> \$newhits" +.$i."[\$a]} \@indices"); eval("\@newhits".$i." = \@newhits".$i."[\@sorted_indices]"); eval("\@newlevel".$i." = \@newlevel".$i."[\@sorted_indices]"); } # find where the next level of the hierarchy is supposed to go for ($i=0; $i<$cutlevelat-1; $i++) { eval ("\$stophere".($i+1)."=0"); eval ("\$meep=\@newlevel".$i); eval ("\$pathlevel=\$pathlevel".($i+1)); for ($x=0; $x<$meep; $x++) { eval ("\$narf=\$newlevel".($i)."[\$x]"); if ($narf eq $pathlevel) { eval ("\$stophere".($i+1)."=\$x"); } } } print "<h1>Individual Page Hits</h1>\n<table border=\"1\" cellpadding= +\"5\">\n"; for($i=0; $i<@mypath; $i++) { print "<tr><td>\n"; my (@path) = split (/\//, $mypath[$i]); print $myhits[$i]."&nbsp;"; print "<a href=\"\">Amherst Steele</a +>"; $temp = ""; $temp1 = "/"; if ($path[1] eq ""){$stop = 1;} $x=1; for ($x=1; $x < @path && $x < $cutat && $x != $stop; $x++) { print "&nbsp;>&nbsp;"; $temp .= $path[$x]; $temp1 .= $path[$x]; $p_count = ($path[$x] =~ tr/\.//); if ($p_count < 1) {$temp.="/"; $temp1.="/";} print "<a href=\"".$temp."\">".$path[$x]."</a>"; } $plvars = "&pathlevel0=$path[$#path]"; $endpath = $path[$#path]; if ($path[$#path] eq $pathlevel0) { print_hierarchy(\@newlevel0, \@newhits0, 1, $stophere1, $plvar +s, $temp, $temp1, $resume); } $p_count = ($endpath =~ /\.//); if ($p_count < 1) { print "&nbsp;<a href=\"/cgi-bin/weblog/ +t=1$plvars\">></a>&nbsp;"; } $stop=0; print "&nbsp;<a href=\"/cgi-bin/weblog/$temp +1&addhits=$myhits[$i]&cutat=$cutat\">+</a>"; print "\n</td></tr>\n"; } print "</table></body></html>";

I'm sure I can scope a lot of these variables a little better, and I'm sure that their are some more efficient ways to do some of the things I was doing (via a built-in function, etc.). If anyone sees anything at all to help sprouse it up, by all means tell me!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2016-10-27 09:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (356 votes). Check out past polls.