Napali.ch
/perl
#!/usr/bin/perl -w
use strict;
use warnings;
use Time::HiRes qw(gettimeofday);
print <<'EOFHEADER';
Memory Anzahl Anzahl Time to Durchschitt Time to Durchschitt
vsz Elemtente search create sec create sec search sec search sec
EOFHEADER
sub ps($) {`ps -p $_[0] -o vsz|tail -1`};
my $mem=ps($$);
my %timecreate;
my %timesearch;
my %hash;
my $tmp;
my $anzahlhash = 2;
my $factoranzahlhash = 2;
my $anzahlsearch = 2;
my $factoranzahlsearch = 2;
my $maxmem = 120_000; # Durch swappen wird der Test verfaelscht!
while ( $mem < $maxmem ) {
$anzahlhash *= $factoranzahlhash;
$anzahlsearch *= $factoranzahlsearch;
$timecreate{"start"} = gettimeofday;
$hash{ "Key" . $_ } = "Value" . $_ for ( 0 .. $anzahlhash );
$timecreate{"end"} = gettimeofday;
$timesearch{"start"} = gettimeofday;
$tmp=$hash{"Key" . int rand($anzahlhash)} for ( 0 .. $anzahlsearch );
$timesearch{"end"} = gettimeofday;
$mem=ps($$);
printf "%6d %9d %9d %12.8f %12.8f %12.8f %12.8f\n",
$mem,
$anzahlhash,
$anzahlsearch,
($timecreate{"end"}-$timecreate{"start"}),
($timecreate{"end"}-$timecreate{"start"})/$anzahlhash,
($timesearch{"end"}-$timesearch{"start"}),
($timesearch{"end"}-$timesearch{"start"})/$anzahlsearch;
}
__END__
$ grep CPU /proc/cpuinfo
model name : Mobile Intel(R) Pentium(R) 4 - M CPU 1.80GHz
$ free
total used free shared buffers cached
Mem: 515812 73164 442648 0 3828 31764
-/+ buffers/cache: 37572 478240
Swap: 0 0 0
$ ./benchmark_hash.pl
Memory Anzahl Anzahl Time to Durchschitt Time to Durchschitt
vsz Elemtente search create sec create sec search sec search sec
6116 4 4 0.00007486 0.00001872 0.00005698 0.00001425
6116 8 8 0.00005889 0.00000736 0.00002694 0.00000337
6116 16 16 0.00008297 0.00000519 0.00004196 0.00000262
6116 32 32 0.00012088 0.00000378 0.00006509 0.00000203
6116 64 64 0.00020409 0.00000319 0.00011396 0.00000178
6116 128 128 0.00045609 0.00000356 0.00021696 0.00000170
6116 256 256 0.00062799 0.00000245 0.00041986 0.00000164
6116 512 512 0.00118494 0.00000231 0.00083399 0.00000163
6116 1024 1024 0.00245500 0.00000240 0.00166988 0.00000163
6248 2048 2048 0.00509095 0.00000249 0.00355983 0.00000174
6548 4096 4096 0.01055503 0.00000258 0.00747609 0.00000183
7204 8192 8192 0.02289104 0.00000279 0.01716805 0.00000210
7992 16384 16384 0.04623103 0.00000282 0.03932595 0.00000240
10212 32768 32768 0.11849213 0.00000362 0.08572197 0.00000262
13748 65536 65536 0.20522594 0.00000313 0.18231606 0.00000278
22736 131072 131072 0.50424004 0.00000385 0.36257410 0.00000277
37000 262144 262144 0.86826992 0.00000331 0.75756598 0.00000289
73060 524288 524288 2.10382009 0.00000401 1.50302100 0.00000287
130104 1048576 1048576 3.56613088 0.00000340 3.17247105 0.00000303
282372 2097152 2097152 8.82272506 0.00000421 6.33559895 0.00000302
461068 4194304 4194304 12.63754106 0.00000301 13.45940518 0.00000321