[PATCH] refactoring patch.diff
Adrian Buehlmann
adrian at cadifra.com
Thu Apr 24 17:59:23 CDT 2008
On 24.04.2008 16:35, TK Soh wrote:
> On Thu, Apr 24, 2008 at 10:24 AM, Dirkjan Ochtman <dirkjan at ochtman.nl> wrote:
>> Adrian Buehlmann wrote:
>> > After spending quite some time analyzing patch.diff, I have refactored it
>> > by moving most of the for loop contents into two new classes.
>>
>> I think this looks nice, but I'd like to know what others think.
>
> As as user, I'll be wondering if there will be any negative
> performance impact. Any benchmark data?
I haven't found any noticeable differences in speed.
I used Mercurial repo changeset 5af5f0f9d724 as test data input.
Details below for those interested.
=== timing current crew ===
> hg par
changeset: 6570:626cb86a6523
tag: tip
user: Benoit Allard <benoit at aeteurope.nl>
date: Thu Apr 24 17:16:02 2008 +0200
summary: add compression type type parameter to bundle command
> hg debugconf
bundle.mainreporoot=C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
paths.default=http://hg.intevation.org/mercurial/crew
ui.username=Adrian Buehlmann <adrian at cadifra.com>
> python probe1.py
timing mercurial.patch.diff (100 calls): 140.77 ms per call
> hg debugconf
bundle.mainreporoot=C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
diff.git=1
paths.default=http://hg.intevation.org/mercurial/crew
ui.username=Adrian Buehlmann <adrian at cadifra.com>
> python probe1.py
timing mercurial.patch.diff (100 calls): 141.74 ms per call
=== timing with patch ===
> hg par
changeset: 6571:e5399a56cd53
tag: tip
user: Adrian Buehlmann <adrian at cadifra.com>
date: Fri Apr 11 00:05:14 2008 +0200
summary: refactoring patch.diff
> hg debugconf
bundle.mainreporoot=C:\Documents and Settings\adi\My Documents\hg-repos\hg-gitdiff
paths.default=C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
ui.username=Adrian Buehlmann <adrian at cadifra.com>
> python probe1.py
timing mercurial.patch.diff (100 calls): 141.82 ms per call
> hg debugconf
bundle.mainreporoot=C:\Documents and Settings\adi\My Documents\hg-repos\hg-gitdiff
diff.git=1
paths.default=C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
ui.username=Adrian Buehlmann <adrian at cadifra.com>
> python probe1.py
timing mercurial.patch.diff (100 calls): 141.86 ms per call
=== probe1.py ===
'''
#some speedtests for
#http://selenic.com/pipermail/mercurial-devel/2008-April/006007.html
from mercurial import ui, hg
from mercurial import patch
from mercurial import util
from os import path
import timeit
repodir = "C:/Documents and Settings/adi/My Documents/hg-repos/hg-crew-testing"
u = ui.ui()
repo = hg.repository(u, repodir)
fp = None
fp = open(path.devnull, 'w')
node1 = repo.lookup('5af5f0f9d724')
node2 = repo.lookup('7855b88ba838')
def f():
patch.diff(repo, node1=node1, node2=node2, files=None, match=util.always,
fp=fp, changes=None, opts=None)
f()
num = 100
timer = timeit.Timer("f()", "from __main__ import f")
print "timing mercurial.patch.diff (%s calls):" % num,
res = timer.timeit(num)
print "%.2f ms per call" % (res / num * 1000.0)
'''
=== lsprof hg export ===
> hgc version
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
Mercurial Distributed SCM (version 626cb86a6523)
> hgt version
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-gitdiff
Mercurial Distributed SCM (version e5399a56cd53)
> cd
C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew-testing
> hg id
626cb86a6523 tip
> hgc debugconfig
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
bundle.mainreporoot=C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew-testing
paths.default=http://hg.intevation.org/mercurial/crew
ui.username=Adrian Buehlmann <adrian at cadifra.com>
> hg log -r 5af5f0f9d724 -v
changeset: 6004:5af5f0f9d724
user: Matt Mackall <mpm at selenic.com>
date: Sun Feb 03 19:29:05 2008 -0600
files: mercurial/commands.py mercurial/filemerge.py tests/run-tests.py tests/test-add.out tests/test-conflict.out
tests/test-convert-svn-sink.out tests/test-copy-move-merge.out tests/test-double-merge.out tests/test-install.out
tests/test-issue672.out tests/test-merge-commit.out tests/test-merge-local.out tests/test-merge-revert2.out
tests/test-merge7.out tests/test-merge9.out tests/test-rename-merge1.out tests/test-rename-merge2.out
tests/test-up-local-change.out
> hgc export -o nul --time 5af5f0f9d724
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
Time: real 0.261 secs (user 0.063+0.000 sys 0.203+0.000)
> hgt export -o nul --time 5af5f0f9d724
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-gitdiff
Time: real 0.261 secs (user 0.109+0.000 sys 0.156+0.000)
> hgc export -o nul --lsprof 5af5f0f9d724
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-crew
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
21 0 0.2506 0.0825 mercurial.revlog:357(parseindex)
+14750 0 0.1044 0.0531 +struct:77(unpack)
+14750 0 0.0220 0.0220 +<method 'append' of 'list' objects>
+21 0 0.0379 0.0008 +mercurial.util_win32:301(read)
+21 0 0.0033 0.0006 +mercurial.util:793(fstat)
+21 0 0.0002 0.0002 +mercurial.revlog:45(gettype)
14771 0 0.1046 0.0532 struct:77(unpack)
+14771 0 0.0514 0.0514 +<method 'unpack' of 'Struct' objects>
+1 0 0.0000 0.0000 +struct:35(_compile)
14771 0 0.0514 0.0514 <method 'unpack' of 'Struct' objects>
77 0 0.0370 0.0370 <win32file.ReadFile>
15088 0 0.0226 0.0226 <method 'append' of 'list' objects>
50 30 0.0288 0.0182 <__import__>
+1 0 0.0023 0.0005 +hashlib:52(<module>)
+1 0 0.0023 0.0004 +mercurial.revlog:11(<module>)
+1 0 0.0073 0.0003 +mercurial.patch:9(<module>)
+1 0 0.0005 0.0002 +mercurial.context:8(<module>)
+1 0 0.0003 0.0002 +encodings.utf_8:8(<module>)
325 0 0.0176 0.0176 <zlib.decompress>
1 0 0.0243 0.0133 mercurial.revlog:833(_partialmatch)
+6573 0 0.0111 0.0111 +<method 'startswith' of 'str' objects>
+1 0 0.0000 0.0000 +<binascii.hexlify>
+2 0 0.0000 0.0000 +<len>
+1 0 0.0000 0.0000 +<binascii.unhexlify>
6621 0 0.0112 0.0112 <method 'startswith' of 'str' objects>
460 0 0.0376 0.0092 mercurial.revlog:869(chunk)
+460 0 0.0019 0.0019 +mercurial.revlog:532(start)
+460 0 0.0193 0.0018 +mercurial.revlog:94(decompress)
+460 0 0.0010 0.0010 +mercurial.revlog:536(length)
+457 0 0.0007 0.0007 +<len>
+9 0 0.0056 0.0003 +mercurial.revlog:870(loadcache)
> hgt export -o nul --lsprof 5af5f0f9d724
--- running hg from C:\Documents and Settings\adi\My Documents\hg-repos\hg-gitdiff
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
21 0 0.2500 0.0816 mercurial.revlog:357(parseindex)
+14750 0 0.1038 0.0529 +struct:77(unpack)
+14750 0 0.0223 0.0223 +<method 'append' of 'list' objects>
+21 0 0.0384 0.0009 +mercurial.util_win32:301(read)
+21 0 0.0035 0.0006 +mercurial.util:793(fstat)
+21 0 0.0002 0.0002 +mercurial.revlog:45(gettype)
14789 0 0.1042 0.0532 struct:77(unpack)
+14789 0 0.0510 0.0510 +<method 'unpack' of 'Struct' objects>
+2 0 0.0000 0.0000 +struct:35(_compile)
14789 0 0.0510 0.0510 <method 'unpack' of 'Struct' objects>
77 0 0.0374 0.0374 <win32file.ReadFile>
15106 0 0.0228 0.0228 <method 'append' of 'list' objects>
326 0 0.0183 0.0183 <zlib.decompress>
52 30 0.0289 0.0182 <__import__>
+1 0 0.0023 0.0005 +hashlib:52(<module>)
+1 0 0.0023 0.0004 +mercurial.revlog:11(<module>)
+1 0 0.0073 0.0003 +mercurial.patch:9(<module>)
+1 0 0.0005 0.0002 +mercurial.context:8(<module>)
+1 0 0.0003 0.0002 +encodings.utf_8:8(<module>)
1 0 0.0243 0.0133 mercurial.revlog:833(_partialmatch)
+6573 0 0.0111 0.0111 +<method 'startswith' of 'str' objects>
+1 0 0.0000 0.0000 +<binascii.hexlify>
+2 0 0.0000 0.0000 +<len>
+1 0 0.0000 0.0000 +<binascii.unhexlify>
6621 0 0.0112 0.0112 <method 'startswith' of 'str' objects>
461 0 0.0377 0.0084 mercurial.revlog:869(chunk)
+461 0 0.0019 0.0019 +mercurial.revlog:532(start)
+461 0 0.0201 0.0018 +mercurial.revlog:94(decompress)
+461 0 0.0010 0.0010 +mercurial.revlog:536(length)
+458 0 0.0007 0.0007 +<len>
+9 0 0.0057 0.0003 +mercurial.revlog:870(loadcache)
More information about the Mercurial-devel
mailing list