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
#!/usr/bin/perl -w use strict; use Time::HiRes qw(gettimeofday tv_interval); my $t0 = [gettimeofday]; my $base_path = "K:/CAD_FAB"; if (!defined($base_path) || $base_path eq '') { die "You need to specify a directory (e.g. 'dir_bot.pl subfolder')!\n"; } my @directorys; my @files_erg; # Durchsucht rekursiv den Path nach Dateien und Verzeichnissen process_files ($base_path); print "\nAnzahl pdw-Files:".scalar(@files_erg)."\n"; # benötigte Zeit ausgeben my $sec = tv_interval($t0); my $min = int($sec/60); my $ms = $1 if( ($sec =~ /\.(\d)/)); $sec = $sec%60; print "\nDie Ausfuehrung dauerte ".$min." Minuten und ".$sec.".".$ms." Sekunden.\n"; exit; # Durchsucht rekursiv den Path nach Dateien .pdw (Unterverzeichnisse eingeschlossen) sub process_files { my $path = shift; opendir (DIR, $path) or die "Unable to open $path: $!\n"; my @files = grep { !/^\.\.?$/ && !-d $_ } readdir (DIR); closedir (DIR); @files = map { $path . '/' . $_ } @files; foreach(@files){ unless(-d $_){ if( $_ =~ /.*\.pdw/ ){ print $_."\n"; push(@files_erg, $_); } } else{ #push(@directorys, $_); process_files ($_); } } }
my $dir
1
2
3
opendir (DIR, $path) or die "Unable to open $path: $!\n";
my @files = grep { !/^\.\.?$/ && !-d $_ } readdir (DIR);
closedir (DIR);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Cwd;
sub process_files {
my $path = shift;
my $dir = getcwd;
chdir( $path ) or die "chdir($path) failed: $!";
opendir (my $dh, ".") or die "Unable to open ".": $!\n";
my @files = grep { !/^\.\.?$/ } readdir ($dh);
closedir ($dh);
foreach(@files){
if ( -d $_ ) {
process_files($_);
}
elsif ( $_ =~ /\.pdw$/ ) {
push @files_erg, $_;
}
}
chdir ( $dir ) or die "chdir($dir) failed: $!\n";
}
1 2 3 4 5 6
use strict; use warnings; use feature qw(say); use File::Find::Rule; say "Anzahl Dateien: " . File::Find::Rule->file()->name("*.pdw")->in("K:/CAD_FAB");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
### Suche im gegebenen Verzeichnis nach *.pod
$ find /usr/lib/perl5 -name "*.pod" | wc -l
299
$ time perl /tmp/find.pl /usr/lib/perl5/
Rate ffrule ffind gustl
ffrule 17.1/s -- -66% -71%
ffind 50.0/s 192% -- -15%
gustl 59.0/s 245% 18% --
# Kontrolle, wie viel wurde gefunden
Gustl: 299
File::Find: 299
File::Find::Rule: 299
real 0m4.197s
user 0m3.240s
sys 0m0.944s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
sub process_files { my @stack=@_; my ($p,$dh,$path); while(@stack) { path = pop(@stack); opendir ($dh, $path) or die "Unable to open $path: $!\n"; for( readdir($dh) ) { next if( $_ eq '.' or $_ eq '..' ); $p=$path.'/'.$_; if( -d $p ) { push(@stack, $p); } elsif( substr($_,-4,4) eq '.pdw' ) { push(@files_erg, $_); } } closedir ($dh); } }
1
2
3
4
5
6
7
8
9
10
11
12
Rate ffrule ffind topeg gustl guspeg
ffrule 17.1/s -- -65% -66% -71% -75%
ffind 49.5/s 189% -- -1% -16% -26%
topeg 50.0/s 192% 1% -- -16% -26%
gustl 59.3/s 246% 20% 19% -- -12%
guspeg 67.3/s 293% 36% 35% 14% --
# Kontrolle
Gustl: 299
topeg: 299
Gustl&topeg: 299
File::Find: 299
File::Find::Rule: 299
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 process_files_1 { my @stack=@_; my $dir=getcwd; my ($p,$dh,$path); while(@stack) { $path = pop(@stack); chdir( $path ) or die "chdir($path) failed: $!";; opendir( $dh, '.' ) or die "Unable to open $path: $!\n"; for( readdir( $dh ) ) { next if( $_ eq '.' or $_ eq '..' ); if( -d $_ ) { push(@stack, $path.'/'.$_); } elsif( substr($_,-4,4) eq '.pod' ) { push(@files_erg, $_); } } closedir ($dh); } chdir ( $dir ) or die "chdir($dir) failed: $!\n"; return $count; }
1
2
3
4
5
6
7
8
9
10
11
12
topeg: 1013
gustl: 1013
ffrule: 1013
ffind: 1013
guspeg: 1013
Rate ffrule ffind gustl guspeg topeg
ffrule 8.17/s -- -6% -57% -60% -70%
ffind 8.73/s 7% -- -54% -58% -68%
gustl 19.2/s 134% 120% -- -7% -29%
guspeg 20.6/s 152% 136% 8% -- -23%
topeg 26.9/s 229% 208% 40% 30% --
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Rate ffrule topeg ffind gustl guspeg topeg2
ffrule 17.1/s -- -66% -66% -71% -74% -80%
topeg 50.5/s 195% -- -0% -15% -24% -42%
ffind 50.5/s 195% 0% -- -15% -24% -42%
gustl 59.3/s 246% 17% 17% -- -11% -32%
guspeg 66.7/s 289% 32% 32% 13% -- -24%
topeg2 87.5/s 411% 73% 73% 48% 31% --
# Kontrolle
Gustl: 299
topeg: 299
topeg2: 299
Gustl&topeg: 299
File::Find: 299
File::Find::Rule: 299
2013-07-04T21:26:53 topegUnd dann sind das noch die Windows-spezifischen Optimierungen von C#. Da werden Teilweise ganz andere Schnittstellen benutzt als bei perl.
Man darf halt nicht vergessen, das perl für unixuide Systeme entwickelt wurde.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
$ time perl fifi.pl /usr/lib/perl5 83 real 0m0.991s user 0m0.756s sys 0m0.228s (0) 2032: murphy@luna ~ $ dmcs -optimize+ fifi.cs && time ./fifi.exe /usr/lib/perl5 83 real 0m2.414s user 0m1.304s sys 0m1.160s (0) 2033: murphy@luna ~ $ fsharpc --optimize+ fifi.fsx && time ./fifi.exe /usr/lib/perl5 F# Compiler for F# 3.0 (Open Source Edition) Freely distributed under the Apache 2.0 Open Source License 83 real 0m2.132s user 0m1.268s sys 0m0.912s