3

I have written a python script to mine bitcoin.

I am however getting only 3k to 300k hashes per second

Here is the code:

import time
import hashlib
import random
import string

size_of_rand_input = int(input("Size of each random string: "))

def id_generator(chars=string.ascii_letters + string.digits):
    return ''.join(random.choice(chars) for _ in range(size_of_rand_input))

def CheckSpeed(number_of_hashes):
    t1 = time.time()
    for x in range(number_of_hashes):
        hashed = hashlib.sha256(str(id_generator()).encode("utf-8"))
    t2 = time.time()
    time_allotted= t2-t1
    returned = (time_allotted, number_of_hashes)
    return returned;

hashes = int(input("How many hashes would you like to perform: "))

x = CheckSpeed(hashes)

print("It took {} seconds to perform {} hashes!\n".format(x[0], x[1]))

1 Answer 1

3

You are limited by your machine clock speed and hashing library performance. Scripting langs are not a good choice for CPU intensive operations.

Also, you are doing hashes sequentially, try multiprocessing: https://docs.python.org/2/library/multiprocessing.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.