Leser: 26
1 2 3 4 5 6 7 8
use Net::IP; use strict; use warnings; # ... # ... do { push @ips, $ip->ip(); } while ( ++$ip );
$x while $x;
2009-05-30T15:46:15 RPerlOder muesste ich das selbst mit Benchmark testen?
1
2
3
4
5
6
7
8
9
10
perl -we'
($m, $i) = @ARGV;
use Benchmark;
timethese($i, {
block => sub { $x = 0; while (++$x < $m) { $x++ } },
noblock => sub { $x = 0; ++$x while ++$x < $m }
});' 100000 1000
Benchmark: timing 1000 iterations of block, noblock...
block: 9 wallclock secs ( 9.10 usr + 0.00 sys = 9.10 CPU) @ 109.89/s (n=1000)
noblock: 8 wallclock secs ( 8.07 usr + 0.00 sys = 8.07 CPU) @ 123.92/s (n=1000)
2009-05-30T15:46:15 RPerlGibt es bei Perl eigentlich auch sowas aehnliches wie
www.phpbench.com ?
push @ips, $ip->{ip} while ++$ip;
1
2
block: 76 wallclock secs (74.97 usr + 0.08 sys = 75.05 CPU) @ 13.32/s (n=1000)
ohne block: 75 wallclock secs (74.97 usr + 0.06 sys = 75.03 CPU) @ 13.33/s (n=1000)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/perl use Net::IP; use Benchmark qw/:all/; my $result = timethese( 1000, { 'block' => sub { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips = (); while ($ip) { push @ips, $ip->ip(); ++$ip; } }, 'ohne block' => sub { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips = (); push @ips, $ip->{'ip'} while ++$ip; }, } );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
sub ip_add_num { my $self = shift; my ($value) = @_; my $ip = $self->intip + $value; my $last = $self->last_int; # Reached the end of the range ? if ($ip > $self->last_int) { return; } my $newb = ip_inttobin($ip, $self->version); $newb = ip_bintoip($newb, $self->version); my $newe = ip_inttobin($last, $self->version); $newe = ip_bintoip($newe, $self->version); my $new = new Net::IP("$newb - $newe"); return ($new); }
2009-05-30T18:21:07 RPerlDie "schuldige" Funktion hab ich ja eigentlich schon:Code (perl): (dl )sub ip_add_num
1 2 3 4 5 6 7 8 9 10 11
use Net::IP; for ( 1 .. 200 ) { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips = (); while ($ip) { push @ips, $ip->ip(); ++$ip; } }
use Math::BigInt lib => 'GMP'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/perl use strict; use warnings; use Net::IP qw(&ip_inttobin &ip_bintoip); use Benchmark qw/:all/; sub new { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips; my $intip=$ip->intip(); while($intip < $ip->last_int()) { $intip++; push(@ips, ip_bintoip(ip_inttobin($intip, $ip->version), $ip->version)); } } sub old { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips = (); while ($ip) { push @ips, $ip->ip(); ++$ip; } } my $result = timethese( 500, { 'new' => \&new, 'old' => \&old } );
1
2
3
Benchmark: timing 500 iterations of new, old...
new: 4 wallclock secs ( 4.20 usr + 0.01 sys = 4.21 CPU) @ 118.76/s (n=500)
old: 57 wallclock secs (54.36 usr + 0.05 sys = 54.41 CPU) @ 9.19/s (n=500)
1 2 3 4 5 6 7 8 9 10 11
use Net::IP; for ( 1 .. 200 ) { my $ip = new Net::IP('217.229.0.134 - 217.229.0.150') or die; my @ips = (); while ($ip) { push @ips, $ip->ip(); ++$ip; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
sidburn@sid:~/perl510$ git diff
diff --git a/lib/site_perl/5.10.0/Net/IP.pm b/lib/site_perl/5.10.0/Net/IP.pm
index eec2023..26f13b4 100644
--- a/lib/site_perl/5.10.0/Net/IP.pm
+++ b/lib/site_perl/5.10.0/Net/IP.pm
@@ -40,7 +40,7 @@
package Net::IP;
use strict;
-use Math::BigInt;
+#use Math::BigInt;
# Global Variables definition
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $ERROR $ERRNO
@@ -388,7 +388,7 @@ sub binmask {
sub size {
my $self = shift;
- my $size = new Math::BigInt($self->last_int);
+ my $size = $self->last_int; #new Math::BigInt($self->last_int);
$size->badd(1);
$size->bsub($self->intip);
@@ -888,7 +888,7 @@ sub ip_bintoint {
my $binip = shift;
# $n is the increment, $dec is the returned value
- my ($n, $dec) = (Math::BigInt->new(1), Math::BigInt->new(0));
+ my ($n, $dec) = (1, 0); #Math::BigInt->new(1), Math::BigInt->new(0));
# Reverse the bit string
@@ -913,7 +913,7 @@ sub ip_bintoint {
# Returns : bit string
sub ip_inttobin {
- my $dec = Math::BigInt->new(shift);
+ my $dec = shift; #Math::BigInt->new(shift);
# Find IP version
my $ip_version = shift;
@@ -924,7 +924,7 @@ sub ip_inttobin {
return;
}
- my $binip = $dec->as_bin();
+ my $binip = sprintf '%b', $dec; #$dec->as_bin();
$binip =~ s/^0b//;
# Define normal size for address