hash = wordreverse(hash)
and could be replaced by
If I am right, then the following small patch will triple the efficiency (from ~32 khash/sec to more than 100 khash/sec):
+++ pyminer-opt.py 2011-02-17 19:47:44.794843788 +0100
@@ -76,18 +76,10 @@
def getwork(self, data=None):
return self.rpc('getwork', data)
-def uint32(x):
- return x & 0xffffffffL
-
-def bytereverse(x):
- return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
- (((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
-
def bufreverse(in_buf):
out_words = []
for i in range(0, len(in_buf), 4):
- word = struct.unpack('@I', in_buf[i:i+4])[0]
- out_words.append(struct.pack('@I', bytereverse(word)))
+ out_words.append(in_buf[i:i+4][::-1])
return ''.join(out_words)
def wordreverse(in_buf):
@@ -115,10 +107,7 @@
hash_o = hashlib.sha256()
hash_o.update(hash1)
- hash = hash_o.digest()
-
- hash = bufreverse(hash)
- hash = wordreverse(hash)
+ hash = hash_o.digest()[::-1]
hash_str = hash.encode('hex')
l = long(hash_str, 16)
A few other optimizations can be made within the loop to raise the efficiency to approx. 110 khash/sec on my machine, but this will make the code less legible and is probably not worth it.
Cheers,