Package: perl Version: 5.8.8-6 Severity: normal Cwd::cwd is implemented somewhat innefficiently, since it uses `pwd` internally:
[EMAIL PROTECTED]:~>perl -e 'use Benchmark ":all"; use Cwd; timethese(10000, { cwd => "Cwd::cwd", getcwd => "Cwd::getcwd", fastcwd => "Cwd::fastcwd" })' Benchmark: timing 10000 iterations of cwd, fastcwd, getcwd... cwd: 8 wallclock secs ( 0.23 usr 1.32 sys + 1.33 cusr 5.58 csys = 8.46 CPU) @ 6451.61/s (n=10000) fastcwd: 0 wallclock secs ( 0.00 usr + 0.01 sys = 0.01 CPU) @ 1000000.00/s (n=10000) (warning: too few iterations for a reliable count) getcwd: 1 wallclock secs ( 0.02 usr + 0.11 sys = 0.13 CPU) @ 76923.08/s (n=10000) (warning: too few iterations for a reliable count) File::Spec::abs2rel though, will use cwd with no way to make it use a faster implementation. To make things worse, it seems to call it twice per call to abs2rel, if both parameters are relative. Once to make each path absolute: [EMAIL PROTECTED]:~>strace -f perl -le 'use File::Spec; print File::Spec->abs2rel("boo/bar", "bar") for 1..2' 2>&1 |grep execve execve("/usr/bin/perl", ["perl", "-le", "use File::Spec; print File::Spec"...], [/* 45 vars */]) = 0 [pid 25300] execve("/bin/pwd", ["/bin/pwd"], [/* 45 vars */] <unfinished ...> [pid 25300] <... execve resumed> ) = 0 [pid 25301] execve("/bin/pwd", ["/bin/pwd"], [/* 45 vars */] <unfinished ...> [pid 25301] <... execve resumed> ) = 0 [pid 25302] execve("/bin/pwd", ["/bin/pwd"], [/* 45 vars */] <unfinished ...> [pid 25302] <... execve resumed> ) = 0 [pid 25303] execve("/bin/pwd", ["/bin/pwd"], [/* 45 vars */] <unfinished ...> [pid 25303] <... execve resumed> ) = 0 [EMAIL PROTECTED]:~>strace -f perl -le 'use File::Spec; print File::Spec->abs2rel("/boo/bar", "/bar")' 2>&1 |grep execve execve("/usr/bin/perl", ["perl", "-le", "use File::Spec; print File::Spec"...], [/* 45 vars */]) = 0 It's highly annoying that it wants to get the cwd at all in this case, since I'm asking for a relative path between two relative directories and indeed the same relative path is returned no matter what the cwd is. I suspect that in this case both calls to cwd could be completly removed. In the meantime, my program ikiwiki, which can sometimes need to calculate thousands or tens of thousands of relative paths per run (one per link in the wiki) is enormously slowed down by this, and I had to make it use the following wrapper: sub abs2rel ($$) { # Work around very innefficient behavior in File::Spec if abs2rel # is passed two relative paths. It's much faster if paths are # absolute! my $path="/".shift; my $base="/".shift; require File::Spec; my $ret=File::Spec->abs2rel($path, $base); $ret=~s/^// if defined $ret; return $ret; } In the case of ikiwiki, this sped up the entire program by about 25%-35%. -- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable'), (1, 'experimental') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.17-1-686 Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Versions of packages perl depends on: ii libc6 2.3.6-15 GNU C Library: Shared libraries ii libdb4.4 4.4.20-6 Berkeley v4.4 Database Libraries [ ii libgdbm3 1.8.3-3 GNU dbm database routines (runtime ii perl-base 5.8.8-6 The Pathologically Eclectic Rubbis ii perl-modules 5.8.8-6 Core Perl modules Versions of packages perl recommends: ii perl-doc 5.8.8-6 Perl documentation -- no debconf information -- see shy jo
signature.asc
Description: Digital signature