[diffoscope] 05/05: Profile the internal and external "cmp" methods separately.
Chris Lamb
chris at chris-lamb.co.uk
Fri Dec 23 11:46:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit ca45370cf762c3a7748835f075ca16c2fdd82ede
Author: Chris Lamb <lamby at debian.org>
Date: Fri Dec 23 11:44:14 2016 +0000
Profile the internal and external "cmp" methods separately.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/binary.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index a6368d8..9f092e5 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -29,6 +29,7 @@ import subprocess
from diffoscope import tool_required, logger
from diffoscope.exc import OutputParsingError, RequiredToolNotFound
from diffoscope.config import Config
+from diffoscope.profiling import profile
from diffoscope.difference import Difference
try:
@@ -187,7 +188,6 @@ class File(object, metaclass=abc.ABCMeta):
difference.add_details(details)
return difference
- @tool_required('cmp')
def has_same_content_as(self, other):
logger.debug('Binary.has_same_content: %s %s', self, other)
# try comparing small files directly first
@@ -200,13 +200,18 @@ class File(object, metaclass=abc.ABCMeta):
return False
if my_size == other_size and my_size <= SMALL_FILE_THRESHOLD:
try:
- with open(self.path, 'rb') as file1, open(other.path, 'rb') as file2:
- return file1.read() == file2.read()
+ with profile('command', 'cmp (internal)'):
+ with open(self.path, 'rb') as file1, open(other.path, 'rb') as file2:
+ return file1.read() == file2.read()
except OSError:
# one or both files could not be opened for some reason,
# assume they are different
return False
+ return self.cmp_external(other)
+
+ @tool_required('cmp')
+ def cmp_external(self, other):
return 0 == subprocess.call(['cmp', '-s', self.path, other.path],
shell=False, close_fds=True)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list