Calculate Hashes/s

How can I calculate how many hashes I generate per second?

I have a function which generates hashes from a string:

string GenerateHash(string plainText);

I generate as many hashes as possible with 4 threads.

How do I calculate how many hashes (or megahashes) I generate per second?

Your problem breaks down nicely into 3 separate tasks

  1. Sharing a single count variable across threads
  2. Benchmarking thread completion time
  3. Calculating hashes per/second

Sharing a single count variable across threads

public static class GlobalCounter
{ public static int Value { get;
private set;
} public static void Increment()
{ Value =GetNextValue(Value);
} private static int GetNextValue(int curValue) { returnInterlocked.Increment(ref curValue);
} public static void Reset() { Value = 0; } }

Before you spin off the threads call GlobalCounter.Reset and then in each thread (after each successful hash) you would call GlobalCounter.Increment – using Interlocked.X performs atomic operations of Value in a thread-safe manner, it’s also much faster than lock.

Benchmarking thread completion time

var sw = Stopwatch.StartNew(); Parallel.ForEach(someCollection, someValue => 
{ // generate hash GlobalCounter.Increment();
}); sw.Stop();

Parallel.ForEach will block until all threads have finished

Calculating hashes per second

... sw.Stop(); var hashesPerSecond = GlobalCounter.Value / sw.Elapsed.Seconds;

Did you find this article helpful?

If so, please consider a donation to help the evolution and development of more helpful articles in the future, and show your support for alternative articles.

Your generosity is 💚 ly appreciated

You can donate in any crypto your 💚 desires 😊

Thank you all for your time !!!

✌ & 💚

Bitcoin (BTC) :
1P1tTNFGRZabK65RhqQxVmcMDHQeRX9dJJ

LiteCoin(LTC) :
LYAdiSpsTJ36EWCJ5HF9EGy9iWGCwoLhed

Ethereum(ETH) :
0x602e8Ca3984943cef57850BBD58b5D0A6677D856

EthereumClassic(ETC) :
0x602e8Ca3984943cef57850BBD58b5D0A6677D856

Cardano(ADA)
addr1q88c5cccnrqy6xesszzvf7rd4tcz87klt0m0h6uvltywqe8txwmsrrqdnpq27594tyn9vz59zv0n8367lvyc2atvrzvqlvdm9d

BinanceCoin(BNB)
bnb1wwfnkzs34knsrv2g026t458l0mwp5a3tykeylx

BitcoinCash (BCH)
1P1tTNFGRZabK65RhqQxVmcMDHQeRX9dJJ

BitcoinSV(BSV)
1P1tTNFGRZabK65RhqQxVmcMDHQeRX9dJJ

ZCash(ZEC)
t1fSSQX4gEhove9ngcvFafQaMPq5dtNNsNF

Dash(DASH)
XcWmbFw1VmxEPxvF9CWdjzKXwPyDTrbMwj

Shiba(SHIB)
0x602e8Ca3984943cef57850BBD58b5D0A6677D856

Tron(TRX)
TCsJJkqt9xk1QZWQ8HqZHnqexR15TEowk8

Stellar(XLM)
GBL4UKPHP2SXZ6Y3PRF3VRI5TLBL6XFUABZCZC7S7KWNSBKCIBGQ2Y54

Made with 💚 by Free Spirit

✌ & 💚

  • Motivation Formula
    Motivation = (Expectancy X Value) / (Impulsiveness X Delay) Add it up, and the result is your current level of motivation.  The less confident you are, the less exciting the outcome, the longer you have to … Continue reading Motivation Formula
  • 21M or Death
    The supply of Bitcoin is fixed at 21 million BTC, and as a hard coded monetary policy of the protocol, the fixed supply of the dominant cryptocurrency cannot be altered. Former Google Product Director Steve Lee … Continue reading 21M or Death
  • Truth Quotes
    In Roman mythology, Veritas, meaning Truth, is the goddess of Truth, a daughter of Chronos, the God of Time. For my dearest copăcel Emily, Wish that you’ll find a drop of wisdom in an ocean of … Continue reading Truth Quotes
  • ₿uild a New Model…
    “You never change things by fighting the existing reality. To change something, build a new model that makes the existing model obsolete.” Buckminster Fuller
  • First Time/Small Miner
    First time/Small miner referencefor getting started. If you want to start mining here is what you need… and what you need to know. This is written for home miners/small farms, but can be used as a … Continue reading First Time/Small Miner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s