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

<p>Also, you are doing hashes sequentially, try multiprocessing: <a href="https://docs.python.org/2/library/multiprocessing.html" rel="nofollow noreferrer">https://docs.python.org/2/library/multiprocessing.html</a></p>

CC BY-SA 3.0
2017-12-22T23:43:12.923Z
2017-12-22T23:43:12.923Z
vent
<p>I have written a python script to mine bitcoin.</p>

<p>I am however getting only 3k to 300k hashes per second</p>

<p>Here is the code: </p>

<pre><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]))
</code></pre>

<hashpower><mining-software><cpu-mining>
Why am I getting only about 3k to 300k hashes per second?
matt
# Why am I getting only about 3k to 300k hashes per second?

(Asked by: username_0 on 2017-12-22)

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]))

```

**Tags:** hashpower, mining-software, cpu-mining


---

## 1 answers

### Answer by username_1 on 2017-12-22. Score: 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>


---

