| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | # Copyright (c) 2000 Josiah Bryan USA | ||||||||||
| 4 | # | ||||||||||
| 5 | # See AUTHOR section in pod text below for usage and distribution rights. | ||||||||||
| 6 | # | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | $System::Index::VERSION = "0.1"; | |||||||||
| 10 | 1 | $System::Index::ID = | |||||||||
| 11 | '$Id: System::Index.pm, v'.$System::Index::VERSION.' 2000/04/09 12:27:05 josiah Exp $'; | ||||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | package System::Index; | ||||||||||
| 15 | |||||||||||
| 16 | 1 | require 5.005_62; | |||||||||
| 17 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use Benchmark; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 1 | require Exporter; | |||||||||
| 22 | 1 | our @ISA = qw(Exporter); | |||||||||
| 23 | 1 | our @EXPORT = qw(cpu_index hd_index mem_index); | |||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | sub cpu_index { | ||||||||
|
Subroutine
cpu_index: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||
| 26 | 1 | ▶ | my $timelen=($_[0])?$_[0]:2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1 | ▶ | my $debug=($_[1])?$_[1]:0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 1 | my (@vals,$len); | |||||||||
| 29 | 1 | my $a=new Benchmark; | |||||||||
| 30 | 1 | $len=0; | |||||||||
| 31 | 1 | ▶ | while($len<$timelen) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 11 | my $_tmp = timeit(10000, '$x=500;$y=12.451252;$z=$x/$y;$z+=$y/$z*$z;'); | |||||||||
| 33 | 11 | push @vals, (@$_tmp)[1]; | |||||||||
| 34 | 11 | my $b=new Benchmark; | |||||||||
| 35 | 11 | my $t=timediff($b,$a); | |||||||||
| 36 | 11 | $len+=(@$t)[1]; | |||||||||
| 37 | 11 | ▶ | print "Count:$len\r" if($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | my $sum=0; | |||||||||
| 41 | 1 | for my $z (0..$#vals-1) { | |||||||||
| 42 | 10 | $sum+=$vals[$z]; | |||||||||
| 43 | } | ||||||||||
| 44 | 1 | return sprintf('%.03f',$sum/$len); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | ▶ | sub hd_index { | ||||||||
|
Subroutine
hd_index: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||
| 48 | 1 | ▶ | my $timelen=($_[0])?$_[0]:2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 1 | ▶ | my $debug=($_[1])?$_[1]:0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 1 | ▶ | my $file=($_[2])?$_[2]:'.hd_index.~$$'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | my (@vals,$len); | |||||||||
| 52 | 1 | my $a=new Benchmark; | |||||||||
| 53 | 1 | $len=0; | |||||||||
| 54 | 1 | ▶ | while($len<$timelen) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 14 | my $_tmp = timeit(100, q{ | |||||||||
| 56 | open(FILE,">$file");for(0..10) { print FILE "$_:" } close(FILE); | ||||||||||
| 57 | open(FILE,"$file");my @lines=<FILE>;close(FILE); | ||||||||||
| 58 | unlink(">$file"); | ||||||||||
| 59 | }); | ||||||||||
| 60 | 14 | push @vals, (@$_tmp)[1]; | |||||||||
| 61 | 14 | my $b=new Benchmark; | |||||||||
| 62 | 14 | my $t=timediff($b,$a); | |||||||||
| 63 | 14 | $len+=(@$t)[1]; | |||||||||
| 64 | 14 | ▶ | print "Count:$len\r" if($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | my $sum=0; | |||||||||
| 68 | 1 | for my $z (0..$#vals-1) { | |||||||||
| 69 | 13 | $sum+=$vals[$z]; | |||||||||
| 70 | } | ||||||||||
| 71 | 1 | return sprintf('%.03f',$sum/$len); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | ▶ | sub mem_index { | ||||||||
|
Subroutine
mem_index: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||
| 75 | 1 | ▶ | my $timelen=($_[0])?$_[0]:2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 1 | ▶ | my $debug=($_[1])?$_[1]:0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 1 | my (@vals,$len); | |||||||||
| 78 | 1 | my $a=new Benchmark; | |||||||||
| 79 | 1 | $len=0; | |||||||||
| 80 | 1 | ▶ | while($len<$timelen) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 14 | my $_tmp = timeit(1000, q{ | |||||||||
| 82 | my @array = [ 777 x 777 ]; | ||||||||||
| 83 | my $hash = { a=> $array[0..100], b=> $array[101..200], c=> $array[201..300] }; | ||||||||||
| 84 | my @tmp; | ||||||||||
| 85 | for my $x (0..$#array-1) {$tmp[$x]=$array[$x]} | ||||||||||
| 86 | my $hash2=$hash; | ||||||||||
| 87 | }); | ||||||||||
| 88 | 14 | push @vals, (@$_tmp)[1]; | |||||||||
| 89 | 14 | my $b=new Benchmark; | |||||||||
| 90 | 14 | my $t=timediff($b,$a); | |||||||||
| 91 | 14 | $len+=(@$t)[1]; | |||||||||
| 92 | 14 | ▶ | print "Count:$len\r" if($debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 1 | my $sum=0; | |||||||||
| 96 | 1 | for my $z (0..$#vals-1) { | |||||||||
| 97 | 13 | $sum+=$vals[$z]; | |||||||||
| 98 | } | ||||||||||
| 99 | 1 | return sprintf('%.03f',$sum/$len); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||