[ python-Bugs-1560179 ] Better/faster implementation of os.path.basename/dirname
SourceForge.net
noreply at sourceforge.net
Tue Oct 17 00:23:42 CEST 2006
Bugs item #1560179, was opened at 2006-09-17 07:55
Message generated for change (Comment added) made by josiahcarlson
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1560179&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Michael Gebetsroither (einsteinmg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Better/faster implementation of os.path.basename/dirname
Initial Comment:
hi,
basename/dirname could do better (especially on long
pathnames)
def basename(p):
return split(p)[1]
def dirname(p):
return split(p)[0]
both construct base and dirname and discard the unused
one.
what about that?
def basename(p):
i = p.rfind('/') + 1
return p[i:]
def dirname(p):
i = p.rfind('/') + 1
return p[:i]
greets,
michael
----------------------------------------------------------------------
Comment By: Josiah Carlson (josiahcarlson)
Date: 2006-10-16 15:23
Message:
Logged In: YES
user_id=341410
I note that in the current SVN, dirname uses a test of "if
head and head != '/'*len(head):" to check for the path being
all /, could be replaced by "if head and head.count('/') !=
len(head):", but it probably isn't terribly important.
----------------------------------------------------------------------
Comment By: Georg Brandl (gbrandl)
Date: 2006-10-12 06:08
Message:
Logged In: YES
user_id=849994
Committed in rev. 52316.
----------------------------------------------------------------------
Comment By: Michael Gebetsroither (einsteinmg)
Date: 2006-09-18 05:42
Message:
Logged In: YES
user_id=1600082
posixpath with this patch passes all test from
test_posixpath cleanly.
benchmark:
basename( 310 ) means basename called with a 310 chars long
path
sum = 0.0435626506805 min = 4.19616699219e-05
posixpath.basename( 310 )
sum = 0.152147769928 min = 0.00014591217041
posixpath_orig.basename( 310 )
sum = 0.0436658859253 min = 4.07695770264e-05
posixpath.basename( 106 )
sum = 0.117312431335 min = 0.000112771987915
posixpath_orig.basename( 106 )
sum = 0.0426909923553 min = 4.07695770264e-05
posixpath.basename( 21 )
sum = 0.113305330276 min = 0.000110864639282
posixpath_orig.basename( 21 )
sum = 0.12392115593 min = 0.000121831893921
posixpath.dirname( 310 )
sum = 0.152860403061 min = 0.00014591217041
posixpath_orig.dirname( 310 )
sum = 0.0942873954773 min = 9.08374786377e-05
posixpath.dirname( 106 )
sum = 0.114937067032 min = 0.000111818313599
posixpath_orig.dirname( 106 )
sum = 0.0918889045715 min = 8.79764556885e-05
posixpath.dirname( 21 )
sum = 0.114675760269 min = 0.000109910964966
posixpath_orig.dirname( 21 )
greets
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1560179&group_id=5470
More information about the Python-bugs-list
mailing list