4 ms·
As a Python developer who recently wrote a pure Python ECDSA/bitcoin library, these are very helpful. However performance is not always better. For example I ha
by sethgecko 8y ago
As a Python developer who recently wrote a pure Python ECDSA/bitcoin library, these are very helpful. However performance is not always better. For example I had this function:
def point_mul(p, d):
n = p
q = None
for i in range(256):
if d & (1 << i):
if q is None:
q = n
else:
q = point_add(q, n)
n = point_add(n, n)
return q
but when i changed the loop to this :
for i in reversed(format(d, 'b')):
if i == '1':
I found out it performed much better.
- tonyarkles 8y agoI 100% expect you're correct in your assertion, but here's the big question: do you know why the latter is faster than the former?
- f311a 8y agoPython uses arbitrary-precision integer representation, so you don't work with bits directly.