mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Merged revisions 56020-56124 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56037 | georg.brandl | 2007-06-19 05:33:20 -0700 (Tue, 19 Jun 2007) | 2 lines Patch #1739659: don't slice dict.keys() in pydoc. ................ r56060 | martin.v.loewis | 2007-06-21 13:00:02 -0700 (Thu, 21 Jun 2007) | 2 lines Regenerate to add True, False, None. ................ r56069 | neal.norwitz | 2007-06-21 22:31:56 -0700 (Thu, 21 Jun 2007) | 1 line Get the doctest working again after adding None, True, and False as kewyords. ................ r56070 | neal.norwitz | 2007-06-21 23:25:33 -0700 (Thu, 21 Jun 2007) | 1 line Add space to error message. ................ r56071 | neal.norwitz | 2007-06-21 23:40:04 -0700 (Thu, 21 Jun 2007) | 6 lines Get pybench working, primarily * Use print function * Stop using string module * Use sorted instead of assuming dict methods return lists * Convert range result to a list ................ r56089 | collin.winter | 2007-06-26 10:31:48 -0700 (Tue, 26 Jun 2007) | 1 line Fix AttributeError in distutils/dir_util.py. ................ r56124 | guido.van.rossum | 2007-06-29 18:04:31 -0700 (Fri, 29 Jun 2007) | 30 lines Merged revisions 56014-56123 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56019 | lars.gustaebel | 2007-06-18 04:42:11 -0700 (Mon, 18 Jun 2007) | 2 lines Added exclude keyword argument to the TarFile.add() method. ........ r56023 | lars.gustaebel | 2007-06-18 13:05:55 -0700 (Mon, 18 Jun 2007) | 3 lines Added missing \versionchanged tag for the new exclude parameter. ........ r56038 | georg.brandl | 2007-06-19 05:36:00 -0700 (Tue, 19 Jun 2007) | 2 lines Bug #1737864: allow empty message in logging format routines. ........ r56040 | georg.brandl | 2007-06-19 05:38:20 -0700 (Tue, 19 Jun 2007) | 2 lines Bug #1739115: make shutil.rmtree docs clear wrt. file deletion. ........ r56084 | georg.brandl | 2007-06-25 08:21:23 -0700 (Mon, 25 Jun 2007) | 2 lines Bug #1742901: document None behavior of shlex.split. ........ r56091 | georg.brandl | 2007-06-27 07:09:56 -0700 (Wed, 27 Jun 2007) | 2 lines Fix a variable name in winreg docs. ........ ................
This commit is contained in:
parent
8ddff70822
commit
486364b821
20 changed files with 286 additions and 253 deletions
|
|
@ -28,6 +28,9 @@ in \POSIX{} mode by default, but uses non-\POSIX{} mode if the
|
||||||
\var{posix} argument is false.
|
\var{posix} argument is false.
|
||||||
\versionadded{2.3}
|
\versionadded{2.3}
|
||||||
\versionchanged[Added the \var{posix} parameter]{2.6}
|
\versionchanged[Added the \var{posix} parameter]{2.6}
|
||||||
|
\note{Since the \function{split()} function instantiates a \class{shlex}
|
||||||
|
instance, passing \code{None} for \var{s} will read the string
|
||||||
|
to split from standard input.}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
The \module{shlex} module defines the following class:
|
The \module{shlex} module defines the following class:
|
||||||
|
|
|
||||||
|
|
@ -91,11 +91,12 @@ file type and creator codes will not be correct.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{rmtree}{path\optional{, ignore_errors\optional{, onerror}}}
|
\begin{funcdesc}{rmtree}{path\optional{, ignore_errors\optional{, onerror}}}
|
||||||
Delete an entire directory tree.\index{directory!deleting}
|
\index{directory!deleting}
|
||||||
If \var{ignore_errors} is true,
|
Delete an entire directory tree (\var{path} must point to a directory).
|
||||||
errors resulting from failed removals will be ignored; if false or
|
If \var{ignore_errors} is true, errors resulting from failed removals
|
||||||
omitted, such errors are handled by calling a handler specified by
|
will be ignored; if false or omitted, such errors are handled by
|
||||||
\var{onerror} or, if that is omitted, they raise an exception.
|
calling a handler specified by \var{onerror} or, if that is omitted,
|
||||||
|
they raise an exception.
|
||||||
|
|
||||||
If \var{onerror} is provided, it must be a callable that accepts
|
If \var{onerror} is provided, it must be a callable that accepts
|
||||||
three parameters: \var{function}, \var{path}, and \var{excinfo}.
|
three parameters: \var{function}, \var{path}, and \var{excinfo}.
|
||||||
|
|
|
||||||
|
|
@ -314,13 +314,17 @@ tar archive several times. Each archive member is represented by a
|
||||||
\end{notice}
|
\end{notice}
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}{add}{name\optional{, arcname\optional{, recursive}}}
|
\begin{methoddesc}{add}{name\optional{, arcname\optional{, recursive\optional{, exclude}}}}
|
||||||
Add the file \var{name} to the archive. \var{name} may be any type
|
Add the file \var{name} to the archive. \var{name} may be any type
|
||||||
of file (directory, fifo, symbolic link, etc.).
|
of file (directory, fifo, symbolic link, etc.).
|
||||||
If given, \var{arcname} specifies an alternative name for the file in the
|
If given, \var{arcname} specifies an alternative name for the file in the
|
||||||
archive. Directories are added recursively by default.
|
archive. Directories are added recursively by default.
|
||||||
This can be avoided by setting \var{recursive} to \constant{False};
|
This can be avoided by setting \var{recursive} to \constant{False}.
|
||||||
the default is \constant{True}.
|
If \var{exclude} is given it must be a function that takes one filename
|
||||||
|
argument and returns a boolean value. Depending on this value the
|
||||||
|
respective file is either excluded (\constant{True}) or added
|
||||||
|
(\constant{False}).
|
||||||
|
\versionchanged[Added the \var{exclude} parameter]{2.6}
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}{addfile}{tarinfo\optional{, fileobj}}
|
\begin{methoddesc}{addfile}{tarinfo\optional{, fileobj}}
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ This module offers the following functions:
|
||||||
\var{key} is an already open key, or one of the predefined
|
\var{key} is an already open key, or one of the predefined
|
||||||
\constant{HKEY_*} constants.
|
\constant{HKEY_*} constants.
|
||||||
|
|
||||||
\var{sub_key} is a string that names the subkey with which the
|
\var{value_name} is a string that names the subkey with which the
|
||||||
value is associated.
|
value is associated.
|
||||||
|
|
||||||
\var{type} is an integer that specifies the type of the data.
|
\var{type} is an integer that specifies the type of the data.
|
||||||
|
|
|
||||||
|
|
@ -719,7 +719,7 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6):
|
||||||
>>> import keyword as _keyword
|
>>> import keyword as _keyword
|
||||||
>>> get_close_matches("wheel", _keyword.kwlist)
|
>>> get_close_matches("wheel", _keyword.kwlist)
|
||||||
['while']
|
['while']
|
||||||
>>> get_close_matches("apple", _keyword.kwlist)
|
>>> get_close_matches("Apple", _keyword.kwlist)
|
||||||
[]
|
[]
|
||||||
>>> get_close_matches("accept", _keyword.kwlist)
|
>>> get_close_matches("accept", _keyword.kwlist)
|
||||||
['except']
|
['except']
|
||||||
|
|
|
||||||
|
|
@ -96,14 +96,12 @@ def create_tree (base_dir, files, mode=0o777, verbose=0, dry_run=0):
|
||||||
for 'mkpath()'."""
|
for 'mkpath()'."""
|
||||||
|
|
||||||
# First get the list of directories to create
|
# First get the list of directories to create
|
||||||
need_dir = {}
|
need_dir = set()
|
||||||
for file in files:
|
for file in files:
|
||||||
need_dir[os.path.join(base_dir, os.path.dirname(file))] = 1
|
need_dir.add(os.path.join(base_dir, os.path.dirname(file)))
|
||||||
need_dirs = need_dir.keys()
|
|
||||||
need_dirs.sort()
|
|
||||||
|
|
||||||
# Now create them
|
# Now create them
|
||||||
for dir in need_dirs:
|
for dir in sorted(need_dir):
|
||||||
mkpath(dir, mode, dry_run=dry_run)
|
mkpath(dir, mode, dry_run=dry_run)
|
||||||
|
|
||||||
# create_tree ()
|
# create_tree ()
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ __all__ = ["iskeyword", "kwlist"]
|
||||||
|
|
||||||
kwlist = [
|
kwlist = [
|
||||||
#--start keywords--
|
#--start keywords--
|
||||||
|
'False',
|
||||||
|
'None',
|
||||||
|
'True',
|
||||||
'and',
|
'and',
|
||||||
'as',
|
'as',
|
||||||
'assert',
|
'assert',
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ class Formatter:
|
||||||
traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
|
traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
|
||||||
s = sio.getvalue()
|
s = sio.getvalue()
|
||||||
sio.close()
|
sio.close()
|
||||||
if s[-1] == "\n":
|
if s[-1:] == "\n":
|
||||||
s = s[:-1]
|
s = s[:-1]
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
@ -427,7 +427,7 @@ class Formatter:
|
||||||
if not record.exc_text:
|
if not record.exc_text:
|
||||||
record.exc_text = self.formatException(record.exc_info)
|
record.exc_text = self.formatException(record.exc_info)
|
||||||
if record.exc_text:
|
if record.exc_text:
|
||||||
if s[-1] != "\n":
|
if s[-1:] != "\n":
|
||||||
s = s + "\n"
|
s = s + "\n"
|
||||||
s = s + record.exc_text
|
s = s + record.exc_text
|
||||||
return s
|
return s
|
||||||
|
|
|
||||||
|
|
@ -1748,17 +1748,16 @@ such as "spam", type "modules spam".
|
||||||
''' % sys.version[:3])
|
''' % sys.version[:3])
|
||||||
|
|
||||||
def list(self, items, columns=4, width=80):
|
def list(self, items, columns=4, width=80):
|
||||||
items = items[:]
|
items = list(sorted(items))
|
||||||
items.sort()
|
colw = width // columns
|
||||||
colw = width / columns
|
rows = (len(items) + columns - 1) // columns
|
||||||
rows = (len(items) + columns - 1) / columns
|
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
for col in range(columns):
|
for col in range(columns):
|
||||||
i = col * rows + row
|
i = col * rows + row
|
||||||
if i < len(items):
|
if i < len(items):
|
||||||
self.output.write(items[i])
|
self.output.write(items[i])
|
||||||
if col < columns - 1:
|
if col < columns - 1:
|
||||||
self.output.write(' ' + ' ' * (colw-1 - len(items[i])))
|
self.output.write(' ' + ' ' * (colw - 1 - len(items[i])))
|
||||||
self.output.write('\n')
|
self.output.write('\n')
|
||||||
|
|
||||||
def listkeywords(self):
|
def listkeywords(self):
|
||||||
|
|
|
||||||
|
|
@ -1925,18 +1925,24 @@ class TarFile(object):
|
||||||
print("link to", tarinfo.linkname, end=' ')
|
print("link to", tarinfo.linkname, end=' ')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def add(self, name, arcname=None, recursive=True):
|
def add(self, name, arcname=None, recursive=True, exclude=None):
|
||||||
"""Add the file `name' to the archive. `name' may be any type of file
|
"""Add the file `name' to the archive. `name' may be any type of file
|
||||||
(directory, fifo, symbolic link, etc.). If given, `arcname'
|
(directory, fifo, symbolic link, etc.). If given, `arcname'
|
||||||
specifies an alternative name for the file in the archive.
|
specifies an alternative name for the file in the archive.
|
||||||
Directories are added recursively by default. This can be avoided by
|
Directories are added recursively by default. This can be avoided by
|
||||||
setting `recursive' to False.
|
setting `recursive' to False. `exclude' is a function that should
|
||||||
|
return True for each filename to be excluded.
|
||||||
"""
|
"""
|
||||||
self._check("aw")
|
self._check("aw")
|
||||||
|
|
||||||
if arcname is None:
|
if arcname is None:
|
||||||
arcname = name
|
arcname = name
|
||||||
|
|
||||||
|
# Exclude pathnames.
|
||||||
|
if exclude is not None and exclude(name):
|
||||||
|
self._dbg(2, "tarfile: Excluded %r" % name)
|
||||||
|
return
|
||||||
|
|
||||||
# Skip if somebody tries to archive the archive...
|
# Skip if somebody tries to archive the archive...
|
||||||
if self.name is not None and os.path.abspath(name) == self.name:
|
if self.name is not None and os.path.abspath(name) == self.name:
|
||||||
self._dbg(2, "tarfile: Skipped %r" % name)
|
self._dbg(2, "tarfile: Skipped %r" % name)
|
||||||
|
|
@ -1949,7 +1955,7 @@ class TarFile(object):
|
||||||
if arcname == ".":
|
if arcname == ".":
|
||||||
arcname = ""
|
arcname = ""
|
||||||
for f in os.listdir(name):
|
for f in os.listdir(name):
|
||||||
self.add(f, os.path.join(arcname, f))
|
self.add(f, os.path.join(arcname, f), recursive, exclude)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._dbg(1, name)
|
self._dbg(1, name)
|
||||||
|
|
@ -1971,7 +1977,7 @@ class TarFile(object):
|
||||||
self.addfile(tarinfo)
|
self.addfile(tarinfo)
|
||||||
if recursive:
|
if recursive:
|
||||||
for f in os.listdir(name):
|
for f in os.listdir(name):
|
||||||
self.add(os.path.join(name, f), os.path.join(arcname, f))
|
self.add(os.path.join(name, f), os.path.join(arcname, f), recursive, exclude)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.addfile(tarinfo)
|
self.addfile(tarinfo)
|
||||||
|
|
|
||||||
|
|
@ -558,6 +558,27 @@ class WriteTest(unittest.TestCase):
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
self.assert_(tar.getnames() == [], "added the archive to itself")
|
self.assert_(tar.getnames() == [], "added the archive to itself")
|
||||||
|
|
||||||
|
def test_exclude(self):
|
||||||
|
tempdir = os.path.join(TEMPDIR, "exclude")
|
||||||
|
os.mkdir(tempdir)
|
||||||
|
try:
|
||||||
|
for name in ("foo", "bar", "baz"):
|
||||||
|
name = os.path.join(tempdir, name)
|
||||||
|
open(name, "wb").close()
|
||||||
|
|
||||||
|
def exclude(name):
|
||||||
|
return os.path.isfile(name)
|
||||||
|
|
||||||
|
tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
|
||||||
|
tar.add(tempdir, arcname="empty_dir", exclude=exclude)
|
||||||
|
tar.close()
|
||||||
|
|
||||||
|
tar = tarfile.open(tmpname, "r")
|
||||||
|
self.assertEqual(len(tar.getmembers()), 1)
|
||||||
|
self.assertEqual(tar.getnames()[0], "empty_dir")
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tempdir)
|
||||||
|
|
||||||
|
|
||||||
class StreamWriteTest(unittest.TestCase):
|
class StreamWriteTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3959,7 +3959,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CANNOT_CATCH_MSG "catching classes that do not inherit from"\
|
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
|
||||||
"BaseException is not allowed"
|
"BaseException is not allowed"
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ or contact the author. All Rights Reserved.
|
||||||
|
|
||||||
__version__ = '1.2'
|
__version__ = '1.2'
|
||||||
|
|
||||||
import sys, getopt, string, glob, os, re, exceptions, traceback
|
import sys, getopt, glob, os, re, traceback
|
||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ def _getopt_flags(options):
|
||||||
l.append(o.name+'=')
|
l.append(o.name+'=')
|
||||||
else:
|
else:
|
||||||
l.append(o.name)
|
l.append(o.name)
|
||||||
return string.join(s,''),l
|
return ''.join(s), l
|
||||||
|
|
||||||
def invisible_input(prompt='>>> '):
|
def invisible_input(prompt='>>> '):
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ _integerRangeRE = re.compile('\s*(-?\d+)\s*-\s*(-?\d+)\s*$')
|
||||||
|
|
||||||
def srange(s,
|
def srange(s,
|
||||||
|
|
||||||
split=string.split,integer=_integerRE,
|
integer=_integerRE,
|
||||||
integerRange=_integerRangeRE):
|
integerRange=_integerRangeRE):
|
||||||
|
|
||||||
""" Converts a textual representation of integer numbers and ranges
|
""" Converts a textual representation of integer numbers and ranges
|
||||||
|
|
@ -116,7 +116,7 @@ def srange(s,
|
||||||
"""
|
"""
|
||||||
l = []
|
l = []
|
||||||
append = l.append
|
append = l.append
|
||||||
for entry in split(s,','):
|
for entry in s.split(','):
|
||||||
m = integer.match(entry)
|
m = integer.match(entry)
|
||||||
if m:
|
if m:
|
||||||
append(int(m.groups()[0]))
|
append(int(m.groups()[0]))
|
||||||
|
|
@ -293,7 +293,7 @@ class Application:
|
||||||
verbose = 0
|
verbose = 0
|
||||||
|
|
||||||
# Internal errors to catch
|
# Internal errors to catch
|
||||||
InternalError = exceptions.Exception
|
InternalError = BaseException
|
||||||
|
|
||||||
# Instance variables:
|
# Instance variables:
|
||||||
values = None # Dictionary of passed options (or default values)
|
values = None # Dictionary of passed options (or default values)
|
||||||
|
|
@ -353,20 +353,20 @@ class Application:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print
|
print()
|
||||||
print '* User Break'
|
print('* User Break')
|
||||||
print
|
print()
|
||||||
rc = 1
|
rc = 1
|
||||||
|
|
||||||
except self.InternalError:
|
except self.InternalError:
|
||||||
print
|
print()
|
||||||
print '* Internal Error (use --debug to display the traceback)'
|
print('* Internal Error (use --debug to display the traceback)')
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print
|
print()
|
||||||
traceback.print_exc(20, sys.stdout)
|
traceback.print_exc(20, sys.stdout)
|
||||||
elif self.verbose:
|
elif self.verbose:
|
||||||
print ' %s: %s' % sys.exc_info()[:2]
|
print(' %s: %s' % sys.exc_info()[:2])
|
||||||
print
|
print()
|
||||||
rc = 1
|
rc = 1
|
||||||
|
|
||||||
raise SystemExit(rc)
|
raise SystemExit(rc)
|
||||||
|
|
@ -449,13 +449,13 @@ class Application:
|
||||||
|
|
||||||
# Try to convert value to integer
|
# Try to convert value to integer
|
||||||
try:
|
try:
|
||||||
value = string.atoi(value)
|
value = int(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Find handler and call it (or count the number of option
|
# Find handler and call it (or count the number of option
|
||||||
# instances on the command line)
|
# instances on the command line)
|
||||||
handlername = 'handle' + string.replace(optionname, '-', '_')
|
handlername = 'handle' + optionname.replace('-', '_')
|
||||||
try:
|
try:
|
||||||
handler = getattr(self, handlername)
|
handler = getattr(self, handlername)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
@ -494,54 +494,55 @@ class Application:
|
||||||
|
|
||||||
self.print_header()
|
self.print_header()
|
||||||
if self.synopsis:
|
if self.synopsis:
|
||||||
print 'Synopsis:'
|
print('Synopsis:')
|
||||||
# To remain backward compatible:
|
# To remain backward compatible:
|
||||||
try:
|
try:
|
||||||
synopsis = self.synopsis % self.name
|
synopsis = self.synopsis % self.name
|
||||||
except (NameError, KeyError, TypeError):
|
except (NameError, KeyError, TypeError):
|
||||||
synopsis = self.synopsis % self.__dict__
|
synopsis = self.synopsis % self.__dict__
|
||||||
print ' ' + synopsis
|
print(' ' + synopsis)
|
||||||
print
|
print()
|
||||||
self.print_options()
|
self.print_options()
|
||||||
if self.version:
|
if self.version:
|
||||||
print 'Version:'
|
print('Version:')
|
||||||
print ' %s' % self.version
|
print(' %s' % self.version)
|
||||||
print
|
print()
|
||||||
if self.about:
|
if self.about:
|
||||||
print string.strip(self.about % self.__dict__)
|
about = self.about % self.__dict__
|
||||||
print
|
print(about.strip())
|
||||||
|
print()
|
||||||
if note:
|
if note:
|
||||||
print '-'*72
|
print('-'*72)
|
||||||
print 'Note:',note
|
print('Note:',note)
|
||||||
print
|
print()
|
||||||
|
|
||||||
def notice(self,note):
|
def notice(self,note):
|
||||||
|
|
||||||
print '-'*72
|
print('-'*72)
|
||||||
print 'Note:',note
|
print('Note:',note)
|
||||||
print '-'*72
|
print('-'*72)
|
||||||
print
|
print()
|
||||||
|
|
||||||
def print_header(self):
|
def print_header(self):
|
||||||
|
|
||||||
print '-'*72
|
print('-'*72)
|
||||||
print self.header % self.__dict__
|
print(self.header % self.__dict__)
|
||||||
print '-'*72
|
print('-'*72)
|
||||||
print
|
print()
|
||||||
|
|
||||||
def print_options(self):
|
def print_options(self):
|
||||||
|
|
||||||
options = self.options
|
options = self.options
|
||||||
print 'Options and default settings:'
|
print('Options and default settings:')
|
||||||
if not options:
|
if not options:
|
||||||
print ' None'
|
print(' None')
|
||||||
return
|
return
|
||||||
long = filter(lambda x: x.prefix == '--', options)
|
long = filter(lambda x: x.prefix == '--', options)
|
||||||
short = filter(lambda x: x.prefix == '-', options)
|
short = filter(lambda x: x.prefix == '-', options)
|
||||||
items = short + long
|
items = short + long
|
||||||
for o in options:
|
for o in options:
|
||||||
print ' ',o
|
print(' ',o)
|
||||||
print
|
print()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Example handlers:
|
# Example handlers:
|
||||||
|
|
@ -579,26 +580,29 @@ class Application:
|
||||||
|
|
||||||
self.debug = 1
|
self.debug = 1
|
||||||
# We don't want to catch internal errors:
|
# We don't want to catch internal errors:
|
||||||
self.InternalError = None
|
class NoErrorToCatch(Exception): pass
|
||||||
|
self.InternalError = NoErrorToCatch
|
||||||
|
|
||||||
def handle__copyright(self,arg):
|
def handle__copyright(self,arg):
|
||||||
|
|
||||||
self.print_header()
|
self.print_header()
|
||||||
print string.strip(self.copyright % self.__dict__)
|
copyright = self.copyright % self.__dict__
|
||||||
print
|
print(copyright.strip())
|
||||||
|
print()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def handle__examples(self,arg):
|
def handle__examples(self,arg):
|
||||||
|
|
||||||
self.print_header()
|
self.print_header()
|
||||||
if self.examples:
|
if self.examples:
|
||||||
print 'Examples:'
|
print('Examples:')
|
||||||
print
|
print()
|
||||||
print string.strip(self.examples % self.__dict__)
|
examples = self.examples % self.__dict__
|
||||||
print
|
print(examples.strip())
|
||||||
|
print()
|
||||||
else:
|
else:
|
||||||
print 'No examples available.'
|
print('No examples available.')
|
||||||
print
|
print()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
|
@ -624,13 +628,13 @@ def _test():
|
||||||
options = [Option('-v','verbose')]
|
options = [Option('-v','verbose')]
|
||||||
|
|
||||||
def handle_v(self,arg):
|
def handle_v(self,arg):
|
||||||
print 'VERBOSE, Yeah !'
|
print('VERBOSE, Yeah !')
|
||||||
|
|
||||||
cmd = MyApplication()
|
cmd = MyApplication()
|
||||||
if not cmd.values['-h']:
|
if not cmd.values['-h']:
|
||||||
cmd.help()
|
cmd.help()
|
||||||
print 'files:',cmd.files
|
print('files:',cmd.files)
|
||||||
print 'Bye...'
|
print('Bye...')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
_test()
|
_test()
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,8 @@ class ListSlicing(Test):
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
n = range(100)
|
n = list(range(100))
|
||||||
r = range(25)
|
r = list(range(25))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
from pybench import Test
|
from pybench import Test
|
||||||
from string import join
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class ConcatStrings(Test):
|
class ConcatStrings(Test):
|
||||||
|
|
@ -11,8 +10,8 @@ class ConcatStrings(Test):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
# Make sure the strings are *not* interned
|
# Make sure the strings are *not* interned
|
||||||
s = join(map(str,range(100)))
|
s = ''.join(map(str,range(100)))
|
||||||
t = join(map(str,range(1,101)))
|
t = ''.join(map(str,range(1,101)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
t + s
|
t + s
|
||||||
|
|
@ -77,8 +76,8 @@ class ConcatStrings(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = join(map(str,range(100)))
|
s = ''.join(map(str,range(100)))
|
||||||
t = join(map(str,range(1,101)))
|
t = ''.join(map(str,range(1,101)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -93,8 +92,8 @@ class CompareStrings(Test):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
# Make sure the strings are *not* interned
|
# Make sure the strings are *not* interned
|
||||||
s = join(map(str,range(10)))
|
s = ''.join(map(str,range(10)))
|
||||||
t = join(map(str,range(10))) + "abc"
|
t = ''.join(map(str,range(10))) + "abc"
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
t < s
|
t < s
|
||||||
|
|
@ -159,8 +158,8 @@ class CompareStrings(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = join(map(str,range(10)))
|
s = ''.join(map(str,range(10)))
|
||||||
t = join(map(str,range(10))) + "abc"
|
t = ''.join(map(str,range(10))) + "abc"
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -175,7 +174,7 @@ class CompareInternedStrings(Test):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
# Make sure the strings *are* interned
|
# Make sure the strings *are* interned
|
||||||
s = sys.intern(join(map(str,range(10))))
|
s = sys.intern(''.join(map(str,range(10))))
|
||||||
t = s
|
t = s
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
@ -241,7 +240,7 @@ class CompareInternedStrings(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = sys.intern(join(map(str,range(10))))
|
s = sys.intern(''.join(map(str,range(10))))
|
||||||
t = s
|
t = s
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
@ -331,7 +330,7 @@ class StringSlicing(Test):
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
s = join(map(str,range(100)))
|
s = ''.join(map(str,range(100)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
||||||
|
|
@ -377,7 +376,7 @@ class StringSlicing(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = join(map(str,range(100)))
|
s = ''.join(map(str,range(100)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -394,10 +393,10 @@ if hasattr('', 'lower'):
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
s = join(map(chr,range(20)),'')
|
s = ''.join(map(chr,range(20)))
|
||||||
t = join(map(chr,range(50)),'')
|
t = ''.join(map(chr,range(50)))
|
||||||
u = join(map(chr,range(100)),'')
|
u = ''.join(map(chr,range(100)))
|
||||||
v = join(map(chr,range(256)),'')
|
v = ''.join(map(chr,range(256)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
||||||
|
|
@ -451,10 +450,10 @@ if hasattr('', 'lower'):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = join(map(chr,range(20)),'')
|
s = ''.join(map(chr,range(20)))
|
||||||
t = join(map(chr,range(50)),'')
|
t = ''.join(map(chr,range(50)))
|
||||||
u = join(map(chr,range(100)),'')
|
u = ''.join(map(chr,range(100)))
|
||||||
v = join(map(chr,range(256)),'')
|
v = ''.join(map(chr,range(256)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ except NameError:
|
||||||
raise ImportError
|
raise ImportError
|
||||||
|
|
||||||
from pybench import Test
|
from pybench import Test
|
||||||
from string import join
|
|
||||||
|
|
||||||
class ConcatUnicode(Test):
|
class ConcatUnicode(Test):
|
||||||
|
|
||||||
|
|
@ -15,8 +14,8 @@ class ConcatUnicode(Test):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
# Make sure the strings are *not* interned
|
# Make sure the strings are *not* interned
|
||||||
s = unicode(join(map(str,range(100))))
|
s = unicode(u''.join(map(str,range(100))))
|
||||||
t = unicode(join(map(str,range(1,101))))
|
t = unicode(u''.join(map(str,range(1,101))))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
t + s
|
t + s
|
||||||
|
|
@ -81,8 +80,8 @@ class ConcatUnicode(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = unicode(join(map(str,range(100))))
|
s = unicode(u''.join(map(str,range(100))))
|
||||||
t = unicode(join(map(str,range(1,101))))
|
t = unicode(u''.join(map(str,range(1,101))))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -97,8 +96,8 @@ class CompareUnicode(Test):
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
# Make sure the strings are *not* interned
|
# Make sure the strings are *not* interned
|
||||||
s = unicode(join(map(str,range(10))))
|
s = unicode(u''.join(map(str,range(10))))
|
||||||
t = unicode(join(map(str,range(10))) + "abc")
|
t = unicode(u''.join(map(str,range(10))) + "abc")
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
t < s
|
t < s
|
||||||
|
|
@ -163,8 +162,8 @@ class CompareUnicode(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = unicode(join(map(str,range(10))))
|
s = unicode(u''.join(map(str,range(10))))
|
||||||
t = unicode(join(map(str,range(10))) + "abc")
|
t = unicode(u''.join(map(str,range(10))) + "abc")
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -253,7 +252,7 @@ class UnicodeSlicing(Test):
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
s = unicode(join(map(str,range(100))))
|
s = unicode(u''.join(map(str,range(100))))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
||||||
|
|
@ -299,7 +298,7 @@ class UnicodeSlicing(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = unicode(join(map(str,range(100))))
|
s = unicode(u''.join(map(str,range(100))))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
@ -314,10 +313,10 @@ class UnicodeMappings(Test):
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
|
||||||
s = join(map(unichr,range(20)),'')
|
s = u''.join(map(unichr,range(20)))
|
||||||
t = join(map(unichr,range(100)),'')
|
t = u''.join(map(unichr,range(100)))
|
||||||
u = join(map(unichr,range(500)),'')
|
u = u''.join(map(unichr,range(500)))
|
||||||
v = join(map(unichr,range(1000)),'')
|
v = u''.join(map(unichr,range(1000)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
|
|
||||||
|
|
@ -371,10 +370,10 @@ class UnicodeMappings(Test):
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
s = join(map(unichr,range(20)),'')
|
s = u''.join(map(unichr,range(20)))
|
||||||
t = join(map(unichr,range(100)),'')
|
t = u''.join(map(unichr,range(100)))
|
||||||
u = join(map(unichr,range(500)),'')
|
u = u''.join(map(unichr,range(500)))
|
||||||
v = join(map(unichr,range(1000)),'')
|
v = u''.join(map(unichr,range(1000)))
|
||||||
|
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ def clockres(timer):
|
||||||
return min_diff
|
return min_diff
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print 'Clock resolution of various timer implementations:'
|
print('Clock resolution of various timer implementations:')
|
||||||
print 'time.clock: %10.3fus' % (clockres(time.clock) * 1e6)
|
print('time.clock: %10.3fus' % (clockres(time.clock) * 1e6))
|
||||||
print 'time.time: %10.3fus' % (clockres(time.time) * 1e6)
|
print('time.time: %10.3fus' % (clockres(time.time) * 1e6))
|
||||||
try:
|
try:
|
||||||
import systimes
|
import systimes
|
||||||
print 'systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6)
|
print('systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||||
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
|
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, time, operator, string, platform
|
import sys, time, operator, platform
|
||||||
from CommandLine import *
|
from CommandLine import *
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -103,7 +103,7 @@ def get_timer(timertype):
|
||||||
def get_machine_details():
|
def get_machine_details():
|
||||||
|
|
||||||
if _debug:
|
if _debug:
|
||||||
print 'Getting machine details...'
|
print('Getting machine details...')
|
||||||
buildno, builddate = platform.python_build()
|
buildno, builddate = platform.python_build()
|
||||||
python = platform.python_version()
|
python = platform.python_version()
|
||||||
try:
|
try:
|
||||||
|
|
@ -146,7 +146,8 @@ def print_machine_details(d, indent=''):
|
||||||
d.get('buildno', 'n/a')),
|
d.get('buildno', 'n/a')),
|
||||||
' Unicode: %s' % d.get('unicode', 'n/a'),
|
' Unicode: %s' % d.get('unicode', 'n/a'),
|
||||||
]
|
]
|
||||||
print indent + string.join(l, '\n' + indent) + '\n'
|
joiner = '\n' + indent
|
||||||
|
print(indent + joiner.join(l) + '\n')
|
||||||
|
|
||||||
### Test baseclass
|
### Test baseclass
|
||||||
|
|
||||||
|
|
@ -280,9 +281,9 @@ class Test:
|
||||||
prep_times.append(t)
|
prep_times.append(t)
|
||||||
min_prep_time = min(prep_times)
|
min_prep_time = min(prep_times)
|
||||||
if _debug:
|
if _debug:
|
||||||
print
|
print()
|
||||||
print 'Calib. prep time = %.6fms' % (
|
print('Calib. prep time = %.6fms' % (
|
||||||
min_prep_time * MILLI_SECONDS)
|
min_prep_time * MILLI_SECONDS))
|
||||||
|
|
||||||
# Time the calibration runs (doing CALIBRATION_LOOPS loops of
|
# Time the calibration runs (doing CALIBRATION_LOOPS loops of
|
||||||
# .calibrate() method calls each)
|
# .calibrate() method calls each)
|
||||||
|
|
@ -298,8 +299,8 @@ class Test:
|
||||||
min_overhead = min(self.overhead_times)
|
min_overhead = min(self.overhead_times)
|
||||||
max_overhead = max(self.overhead_times)
|
max_overhead = max(self.overhead_times)
|
||||||
if _debug:
|
if _debug:
|
||||||
print 'Calib. overhead time = %.6fms' % (
|
print('Calib. overhead time = %.6fms' % (
|
||||||
min_overhead * MILLI_SECONDS)
|
min_overhead * MILLI_SECONDS))
|
||||||
if min_overhead < 0.0:
|
if min_overhead < 0.0:
|
||||||
raise ValueError('calibration setup did not work')
|
raise ValueError('calibration setup did not work')
|
||||||
if max_overhead - min_overhead > 0.1:
|
if max_overhead - min_overhead > 0.1:
|
||||||
|
|
@ -436,7 +437,7 @@ class Benchmark:
|
||||||
# Init vars
|
# Init vars
|
||||||
self.tests = {}
|
self.tests = {}
|
||||||
if _debug:
|
if _debug:
|
||||||
print 'Getting machine details...'
|
print('Getting machine details...')
|
||||||
self.machine_details = get_machine_details()
|
self.machine_details = get_machine_details()
|
||||||
|
|
||||||
# Make .version an instance attribute to have it saved in the
|
# Make .version an instance attribute to have it saved in the
|
||||||
|
|
@ -473,8 +474,8 @@ class Benchmark:
|
||||||
|
|
||||||
# Add tests
|
# Add tests
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print 'Searching for tests ...'
|
print('Searching for tests ...')
|
||||||
print '--------------------------------------'
|
print('--------------------------------------')
|
||||||
for testclass in setupmod.__dict__.values():
|
for testclass in setupmod.__dict__.values():
|
||||||
if not hasattr(testclass, 'is_a_test'):
|
if not hasattr(testclass, 'is_a_test'):
|
||||||
continue
|
continue
|
||||||
|
|
@ -488,77 +489,74 @@ class Benchmark:
|
||||||
warp=self.warp,
|
warp=self.warp,
|
||||||
calibration_runs=self.calibration_runs,
|
calibration_runs=self.calibration_runs,
|
||||||
timer=self.timer)
|
timer=self.timer)
|
||||||
l = self.tests.keys()
|
l = sorted(self.tests)
|
||||||
l.sort()
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
for name in l:
|
for name in l:
|
||||||
print ' %s' % name
|
print(' %s' % name)
|
||||||
print '--------------------------------------'
|
print('--------------------------------------')
|
||||||
print ' %i tests found' % len(l)
|
print(' %i tests found' % len(l))
|
||||||
print
|
print()
|
||||||
|
|
||||||
def calibrate(self):
|
def calibrate(self):
|
||||||
|
|
||||||
print 'Calibrating tests. Please wait...',
|
print('Calibrating tests. Please wait...', end=' ')
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print
|
print()
|
||||||
print
|
print()
|
||||||
print 'Test min max'
|
print('Test min max')
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
tests = self.tests.items()
|
tests = sorted(self.tests.items())
|
||||||
tests.sort()
|
|
||||||
for i in range(len(tests)):
|
for i in range(len(tests)):
|
||||||
name, test = tests[i]
|
name, test = tests[i]
|
||||||
test.calibrate_test()
|
test.calibrate_test()
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print '%30s: %6.3fms %6.3fms' % \
|
print('%30s: %6.3fms %6.3fms' % \
|
||||||
(name,
|
(name,
|
||||||
min(test.overhead_times) * MILLI_SECONDS,
|
min(test.overhead_times) * MILLI_SECONDS,
|
||||||
max(test.overhead_times) * MILLI_SECONDS)
|
max(test.overhead_times) * MILLI_SECONDS))
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print
|
print()
|
||||||
print 'Done with the calibration.'
|
print('Done with the calibration.')
|
||||||
else:
|
else:
|
||||||
print 'done.'
|
print('done.')
|
||||||
print
|
print()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
tests = self.tests.items()
|
tests = sorted(self.tests.items())
|
||||||
tests.sort()
|
|
||||||
timer = self.get_timer()
|
timer = self.get_timer()
|
||||||
print 'Running %i round(s) of the suite at warp factor %i:' % \
|
print('Running %i round(s) of the suite at warp factor %i:' % \
|
||||||
(self.rounds, self.warp)
|
(self.rounds, self.warp))
|
||||||
print
|
print()
|
||||||
self.roundtimes = []
|
self.roundtimes = []
|
||||||
for i in range(self.rounds):
|
for i in range(self.rounds):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print ' Round %-25i effective absolute overhead' % (i+1)
|
print(' Round %-25i effective absolute overhead' % (i+1))
|
||||||
total_eff_time = 0.0
|
total_eff_time = 0.0
|
||||||
for j in range(len(tests)):
|
for j in range(len(tests)):
|
||||||
name, test = tests[j]
|
name, test = tests[j]
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print '%30s:' % name,
|
print('%30s:' % name, end=' ')
|
||||||
test.run()
|
test.run()
|
||||||
(eff_time, abs_time, min_overhead) = test.last_timing
|
(eff_time, abs_time, min_overhead) = test.last_timing
|
||||||
total_eff_time = total_eff_time + eff_time
|
total_eff_time = total_eff_time + eff_time
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print ' %5.0fms %5.0fms %7.3fms' % \
|
print(' %5.0fms %5.0fms %7.3fms' % \
|
||||||
(eff_time * MILLI_SECONDS,
|
(eff_time * MILLI_SECONDS,
|
||||||
abs_time * MILLI_SECONDS,
|
abs_time * MILLI_SECONDS,
|
||||||
min_overhead * MILLI_SECONDS)
|
min_overhead * MILLI_SECONDS))
|
||||||
self.roundtimes.append(total_eff_time)
|
self.roundtimes.append(total_eff_time)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print (' '
|
print((' '
|
||||||
' ------------------------------')
|
' ------------------------------'))
|
||||||
print (' '
|
print((' '
|
||||||
' Totals: %6.0fms' %
|
' Totals: %6.0fms' %
|
||||||
(total_eff_time * MILLI_SECONDS))
|
(total_eff_time * MILLI_SECONDS)))
|
||||||
print
|
print()
|
||||||
else:
|
else:
|
||||||
print '* Round %i done in %.3f seconds.' % (i+1,
|
print('* Round %i done in %.3f seconds.' % (i+1,
|
||||||
total_eff_time)
|
total_eff_time))
|
||||||
print
|
print()
|
||||||
|
|
||||||
def stat(self):
|
def stat(self):
|
||||||
|
|
||||||
|
|
@ -583,25 +581,24 @@ class Benchmark:
|
||||||
|
|
||||||
def print_header(self, title='Benchmark'):
|
def print_header(self, title='Benchmark'):
|
||||||
|
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
print '%s: %s' % (title, self.name)
|
print('%s: %s' % (title, self.name))
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
print
|
print()
|
||||||
print ' Rounds: %s' % self.rounds
|
print(' Rounds: %s' % self.rounds)
|
||||||
print ' Warp: %s' % self.warp
|
print(' Warp: %s' % self.warp)
|
||||||
print ' Timer: %s' % self.timer
|
print(' Timer: %s' % self.timer)
|
||||||
print
|
print()
|
||||||
if self.machine_details:
|
if self.machine_details:
|
||||||
print_machine_details(self.machine_details, indent=' ')
|
print_machine_details(self.machine_details, indent=' ')
|
||||||
print
|
print()
|
||||||
|
|
||||||
def print_benchmark(self, hidenoise=0, limitnames=None):
|
def print_benchmark(self, hidenoise=0, limitnames=None):
|
||||||
|
|
||||||
print ('Test '
|
print(('Test '
|
||||||
' minimum average operation overhead')
|
' minimum average operation overhead'))
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
tests = self.tests.items()
|
tests = sorted(self.tests.items())
|
||||||
tests.sort()
|
|
||||||
total_min_time = 0.0
|
total_min_time = 0.0
|
||||||
total_avg_time = 0.0
|
total_avg_time = 0.0
|
||||||
for name, test in tests:
|
for name, test in tests:
|
||||||
|
|
@ -615,43 +612,42 @@ class Benchmark:
|
||||||
min_overhead) = test.stat()
|
min_overhead) = test.stat()
|
||||||
total_min_time = total_min_time + min_time
|
total_min_time = total_min_time + min_time
|
||||||
total_avg_time = total_avg_time + avg_time
|
total_avg_time = total_avg_time + avg_time
|
||||||
print '%30s: %5.0fms %5.0fms %6.2fus %7.3fms' % \
|
print('%30s: %5.0fms %5.0fms %6.2fus %7.3fms' % \
|
||||||
(name,
|
(name,
|
||||||
min_time * MILLI_SECONDS,
|
min_time * MILLI_SECONDS,
|
||||||
avg_time * MILLI_SECONDS,
|
avg_time * MILLI_SECONDS,
|
||||||
op_avg * MICRO_SECONDS,
|
op_avg * MICRO_SECONDS,
|
||||||
min_overhead *MILLI_SECONDS)
|
min_overhead *MILLI_SECONDS))
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
print ('Totals: '
|
print(('Totals: '
|
||||||
' %6.0fms %6.0fms' %
|
' %6.0fms %6.0fms' %
|
||||||
(total_min_time * MILLI_SECONDS,
|
(total_min_time * MILLI_SECONDS,
|
||||||
total_avg_time * MILLI_SECONDS,
|
total_avg_time * MILLI_SECONDS,
|
||||||
))
|
)))
|
||||||
print
|
print()
|
||||||
|
|
||||||
def print_comparison(self, compare_to, hidenoise=0, limitnames=None):
|
def print_comparison(self, compare_to, hidenoise=0, limitnames=None):
|
||||||
|
|
||||||
# Check benchmark versions
|
# Check benchmark versions
|
||||||
if compare_to.version != self.version:
|
if compare_to.version != self.version:
|
||||||
print ('* Benchmark versions differ: '
|
print(('* Benchmark versions differ: '
|
||||||
'cannot compare this benchmark to "%s" !' %
|
'cannot compare this benchmark to "%s" !' %
|
||||||
compare_to.name)
|
compare_to.name))
|
||||||
print
|
print()
|
||||||
self.print_benchmark(hidenoise=hidenoise,
|
self.print_benchmark(hidenoise=hidenoise,
|
||||||
limitnames=limitnames)
|
limitnames=limitnames)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Print header
|
# Print header
|
||||||
compare_to.print_header('Comparing with')
|
compare_to.print_header('Comparing with')
|
||||||
print ('Test '
|
print(('Test '
|
||||||
' minimum run-time average run-time')
|
' minimum run-time average run-time'))
|
||||||
print (' '
|
print((' '
|
||||||
' this other diff this other diff')
|
' this other diff this other diff'))
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
|
|
||||||
# Print test comparisons
|
# Print test comparisons
|
||||||
tests = self.tests.items()
|
tests = sorted(self.tests.items())
|
||||||
tests.sort()
|
|
||||||
total_min_time = other_total_min_time = 0.0
|
total_min_time = other_total_min_time = 0.0
|
||||||
total_avg_time = other_total_avg_time = 0.0
|
total_avg_time = other_total_avg_time = 0.0
|
||||||
benchmarks_compatible = self.compatible(compare_to)
|
benchmarks_compatible = self.compatible(compare_to)
|
||||||
|
|
@ -704,15 +700,15 @@ class Benchmark:
|
||||||
# Benchmark or tests are not comparible
|
# Benchmark or tests are not comparible
|
||||||
min_diff, avg_diff = 'n/a', 'n/a'
|
min_diff, avg_diff = 'n/a', 'n/a'
|
||||||
tests_compatible = 0
|
tests_compatible = 0
|
||||||
print '%30s: %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % \
|
print('%30s: %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % \
|
||||||
(name,
|
(name,
|
||||||
min_time * MILLI_SECONDS,
|
min_time * MILLI_SECONDS,
|
||||||
other_min_time * MILLI_SECONDS * compare_to.warp / self.warp,
|
other_min_time * MILLI_SECONDS * compare_to.warp / self.warp,
|
||||||
min_diff,
|
min_diff,
|
||||||
avg_time * MILLI_SECONDS,
|
avg_time * MILLI_SECONDS,
|
||||||
other_avg_time * MILLI_SECONDS * compare_to.warp / self.warp,
|
other_avg_time * MILLI_SECONDS * compare_to.warp / self.warp,
|
||||||
avg_diff)
|
avg_diff))
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
|
|
||||||
# Summarise test results
|
# Summarise test results
|
||||||
if not benchmarks_compatible or not tests_compatible:
|
if not benchmarks_compatible or not tests_compatible:
|
||||||
|
|
@ -730,7 +726,7 @@ class Benchmark:
|
||||||
(other_total_avg_time * compare_to.warp) - 1.0) * PERCENT)
|
(other_total_avg_time * compare_to.warp) - 1.0) * PERCENT)
|
||||||
else:
|
else:
|
||||||
avg_diff = 'n/a'
|
avg_diff = 'n/a'
|
||||||
print ('Totals: '
|
print(('Totals: '
|
||||||
' %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' %
|
' %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' %
|
||||||
(total_min_time * MILLI_SECONDS,
|
(total_min_time * MILLI_SECONDS,
|
||||||
(other_total_min_time * compare_to.warp/self.warp
|
(other_total_min_time * compare_to.warp/self.warp
|
||||||
|
|
@ -740,11 +736,11 @@ class Benchmark:
|
||||||
(other_total_avg_time * compare_to.warp/self.warp
|
(other_total_avg_time * compare_to.warp/self.warp
|
||||||
* MILLI_SECONDS),
|
* MILLI_SECONDS),
|
||||||
avg_diff
|
avg_diff
|
||||||
))
|
)))
|
||||||
print
|
print()
|
||||||
print '(this=%s, other=%s)' % (self.name,
|
print('(this=%s, other=%s)' % (self.name,
|
||||||
compare_to.name)
|
compare_to.name))
|
||||||
print
|
print()
|
||||||
|
|
||||||
class PyBenchCmdline(Application):
|
class PyBenchCmdline(Application):
|
||||||
|
|
||||||
|
|
@ -823,8 +819,8 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
limitnames = self.values['-t']
|
limitnames = self.values['-t']
|
||||||
if limitnames:
|
if limitnames:
|
||||||
if _debug:
|
if _debug:
|
||||||
print '* limiting test names to one with substring "%s"' % \
|
print('* limiting test names to one with substring "%s"' % \
|
||||||
limitnames
|
limitnames)
|
||||||
limitnames = re.compile(limitnames, re.I)
|
limitnames = re.compile(limitnames, re.I)
|
||||||
else:
|
else:
|
||||||
limitnames = None
|
limitnames = None
|
||||||
|
|
@ -833,26 +829,26 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
calibration_runs = self.values['-C']
|
calibration_runs = self.values['-C']
|
||||||
timer = self.values['--timer']
|
timer = self.values['--timer']
|
||||||
|
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
print 'PYBENCH %s' % __version__
|
print('PYBENCH %s' % __version__)
|
||||||
print '-' * LINE
|
print('-' * LINE)
|
||||||
print '* using %s %s' % (
|
print('* using %s %s' % (
|
||||||
platform.python_implementation(),
|
platform.python_implementation(),
|
||||||
string.join(string.split(sys.version), ' '))
|
' '.join(sys.version.split())))
|
||||||
|
|
||||||
# Switch off garbage collection
|
# Switch off garbage collection
|
||||||
if not withgc:
|
if not withgc:
|
||||||
try:
|
try:
|
||||||
import gc
|
import gc
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print '* Python version doesn\'t support garbage collection'
|
print('* Python version doesn\'t support garbage collection')
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
gc.disable()
|
gc.disable()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
print '* Python version doesn\'t support gc.disable'
|
print('* Python version doesn\'t support gc.disable')
|
||||||
else:
|
else:
|
||||||
print '* disabled garbage collection'
|
print('* disabled garbage collection')
|
||||||
|
|
||||||
# "Disable" sys check interval
|
# "Disable" sys check interval
|
||||||
if not withsyscheck:
|
if not withsyscheck:
|
||||||
|
|
@ -861,18 +857,18 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
try:
|
try:
|
||||||
sys.setcheckinterval(value)
|
sys.setcheckinterval(value)
|
||||||
except (AttributeError, NotImplementedError):
|
except (AttributeError, NotImplementedError):
|
||||||
print '* Python version doesn\'t support sys.setcheckinterval'
|
print('* Python version doesn\'t support sys.setcheckinterval')
|
||||||
else:
|
else:
|
||||||
print '* system check interval set to maximum: %s' % value
|
print('* system check interval set to maximum: %s' % value)
|
||||||
|
|
||||||
if timer == TIMER_SYSTIMES_PROCESSTIME:
|
if timer == TIMER_SYSTIMES_PROCESSTIME:
|
||||||
import systimes
|
import systimes
|
||||||
print '* using timer: systimes.processtime (%s)' % \
|
print('* using timer: systimes.processtime (%s)' % \
|
||||||
systimes.SYSTIMES_IMPLEMENTATION
|
systimes.SYSTIMES_IMPLEMENTATION)
|
||||||
else:
|
else:
|
||||||
print '* using timer: %s' % timer
|
print('* using timer: %s' % timer)
|
||||||
|
|
||||||
print
|
print()
|
||||||
|
|
||||||
if compare_to:
|
if compare_to:
|
||||||
try:
|
try:
|
||||||
|
|
@ -882,9 +878,9 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
f.close()
|
f.close()
|
||||||
compare_to = bench
|
compare_to = bench
|
||||||
except IOError as reason:
|
except IOError as reason:
|
||||||
print '* Error opening/reading file %s: %s' % (
|
print('* Error opening/reading file %s: %s' % (
|
||||||
repr(compare_to),
|
repr(compare_to),
|
||||||
reason)
|
reason))
|
||||||
compare_to = None
|
compare_to = None
|
||||||
|
|
||||||
if show_bench:
|
if show_bench:
|
||||||
|
|
@ -902,16 +898,16 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
bench.print_benchmark(hidenoise=hidenoise,
|
bench.print_benchmark(hidenoise=hidenoise,
|
||||||
limitnames=limitnames)
|
limitnames=limitnames)
|
||||||
except IOError as reason:
|
except IOError as reason:
|
||||||
print '* Error opening/reading file %s: %s' % (
|
print('* Error opening/reading file %s: %s' % (
|
||||||
repr(show_bench),
|
repr(show_bench),
|
||||||
reason)
|
reason))
|
||||||
print
|
print()
|
||||||
return
|
return
|
||||||
|
|
||||||
if reportfile:
|
if reportfile:
|
||||||
print 'Creating benchmark: %s (rounds=%i, warp=%i)' % \
|
print('Creating benchmark: %s (rounds=%i, warp=%i)' % \
|
||||||
(reportfile, rounds, warp)
|
(reportfile, rounds, warp))
|
||||||
print
|
print()
|
||||||
|
|
||||||
# Create benchmark object
|
# Create benchmark object
|
||||||
bench = Benchmark(reportfile,
|
bench = Benchmark(reportfile,
|
||||||
|
|
@ -925,9 +921,9 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
bench.calibrate()
|
bench.calibrate()
|
||||||
bench.run()
|
bench.run()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print
|
print()
|
||||||
print '*** KeyboardInterrupt -- Aborting'
|
print('*** KeyboardInterrupt -- Aborting')
|
||||||
print
|
print()
|
||||||
return
|
return
|
||||||
bench.print_header()
|
bench.print_header()
|
||||||
if compare_to:
|
if compare_to:
|
||||||
|
|
@ -948,12 +944,12 @@ python pybench.py -s p25.pybench -c p21.pybench
|
||||||
pickle.dump(bench,f)
|
pickle.dump(bench,f)
|
||||||
f.close()
|
f.close()
|
||||||
except IOError as reason:
|
except IOError as reason:
|
||||||
print '* Error opening/writing reportfile'
|
print('* Error opening/writing reportfile')
|
||||||
except IOError as reason:
|
except IOError as reason:
|
||||||
print '* Error opening/writing reportfile %s: %s' % (
|
print('* Error opening/writing reportfile %s: %s' % (
|
||||||
reportfile,
|
reportfile,
|
||||||
reason)
|
reason))
|
||||||
print
|
print()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
PyBenchCmdline()
|
PyBenchCmdline()
|
||||||
|
|
|
||||||
|
|
@ -185,27 +185,27 @@ def some_workload():
|
||||||
x = x + 1
|
x = x + 1
|
||||||
|
|
||||||
def test_workload():
|
def test_workload():
|
||||||
print 'Testing systimes() under load conditions'
|
print('Testing systimes() under load conditions')
|
||||||
t0 = systimes()
|
t0 = systimes()
|
||||||
some_workload()
|
some_workload()
|
||||||
t1 = systimes()
|
t1 = systimes()
|
||||||
print 'before:', t0
|
print('before:', t0)
|
||||||
print 'after:', t1
|
print('after:', t1)
|
||||||
print 'differences:', (t1[0] - t0[0], t1[1] - t0[1])
|
print('differences:', (t1[0] - t0[0], t1[1] - t0[1]))
|
||||||
print
|
print()
|
||||||
|
|
||||||
def test_idle():
|
def test_idle():
|
||||||
print 'Testing systimes() under idle conditions'
|
print('Testing systimes() under idle conditions')
|
||||||
t0 = systimes()
|
t0 = systimes()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
t1 = systimes()
|
t1 = systimes()
|
||||||
print 'before:', t0
|
print('before:', t0)
|
||||||
print 'after:', t1
|
print('after:', t1)
|
||||||
print 'differences:', (t1[0] - t0[0], t1[1] - t0[1])
|
print('differences:', (t1[0] - t0[0], t1[1] - t0[1]))
|
||||||
print
|
print()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print 'Using %s as timer' % SYSTIMES_IMPLEMENTATION
|
print('Using %s as timer' % SYSTIMES_IMPLEMENTATION)
|
||||||
print
|
print()
|
||||||
test_workload()
|
test_workload()
|
||||||
test_idle()
|
test_idle()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ mkdir -p OUT
|
||||||
>SKIPPED
|
>SKIPPED
|
||||||
|
|
||||||
# The -u flag (edit this file to change).
|
# The -u flag (edit this file to change).
|
||||||
UFLAG="-unetwork"
|
UFLAG=""
|
||||||
|
|
||||||
# Compute the list of tests to run.
|
# Compute the list of tests to run.
|
||||||
case $# in
|
case $# in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue