Mercurial > hg
view tests/mockblackbox.py @ 31370:906be86990c4
rbc: use struct unpack_from and pack_into instead of unpack and pack
These functions were introduced in Python 2.5 and are faster and simpler than
the old ones ... mainly because we can avoid intermediate buffers:
$ python -m timeit -s "_rbcrecfmt='>4sI'" -s 's = "x"*10000' -s 'from struct import unpack' 'unpack(_rbcrecfmt, buffer(s, 16, 8))'
1000000 loops, best of 3: 0.543 usec per loop
$ python -m timeit -s "_rbcrecfmt='>4sI'" -s 's = "x"*10000' -s 'from struct import unpack_from' 'unpack_from(_rbcrecfmt, s, 16)'
1000000 loops, best of 3: 0.323 usec per loop
$ python -m timeit -s "from array import array" -s "_rbcrecfmt='>4sI'" -s "s = array('c')" -s 's.fromstring("x"*10000)' -s 'from struct import pack' -s "rec = array('c')" 'rec.fromstring(pack(_rbcrecfmt, "asdf", 7))'
1000000 loops, best of 3: 0.364 usec per loop
$ python -m timeit -s "from array import array" -s "_rbcrecfmt='>4sI'" -s "s = array('c')" -s 's.fromstring("x"*10000)' -s 'from struct import pack_into' -s "rec = array('c')" -s 'rec.fromstring("x"*100)' 'pack_into(_rbcrecfmt, rec, 0, "asdf", 7)'
1000000 loops, best of 3: 0.229 usec per loop
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 19 Oct 2016 02:46:35 +0200 |
parents | 417380aa5bbe |
children | 043948c84647 |
line wrap: on
line source
from __future__ import absolute_import from mercurial import ( util, ) def makedate(): return 0, 0 def getuser(): return 'bob' def getpid(): return 5000 # mock the date and user apis so the output is always the same def uisetup(ui): util.makedate = makedate util.getuser = getuser util.getpid = getpid