Bitcoin Forum
June 24, 2024, 06:01:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / Re: how many sha256 hashes can a consumer-grade CPU compute per second in average? on: October 26, 2023, 01:53:22 PM
Using the code provided by seek3r, with some adaptions (such as using more recent package versions for the sha2 and digests crates) I was able to obtain around over 3 million double sha256 hashes per second with 2 threads. I actually computed double sha256 hashes (the output of the first digest being the input for the second), so it would be 6 million single hashes. The tests were done in a x86_64 architecture machine, running 2 threads, and each thread ran on a Intel CPU with 2.60 GHz (upper bound 4GHz).
2  Bitcoin / Development & Technical Discussion / Re: how many sha256 hashes can a consumer-grade CPU compute per second in average? on: October 26, 2023, 01:46:08 PM
I have a linux machine, x86_64 architecture, 4-core Intel. Thank you!

Alright thanks. Tried something on Rust.
You can test around with the NUM_THREADS - set it to 8 if your cpu supports hyper-threading. You can test around and increase NUM_HASHES by every round to get a more precise result.

Since I used crypto and rayon crates you have to add them as dependencies on your cargo.toml with their latest versions:

Code:
[dependencies]
crypto = "0.2.36"
rayon = "1.8.0"

After that, implement this code:

Code:
extern crate crypto;
extern crate rayon;

use crypto::digest::Digest;
use crypto::sha2::Sha256;
use rayon::prelude::*;
use std::time::Instant;

const NUM_HASHES: usize = 1000000;
const NUM_THREADS: usize = 4;

fn compute_hashes() {
    let string = "sha256_maxhash".as_bytes();
    let mut sha = Sha256::new();
    for _ in 0..NUM_HASHES {
        sha.input(string);
        let _ = sha.result_str();
        sha.reset();
    }
}

fn main() {
    rayon::ThreadPoolBuilder::new()
        .num_threads(NUM_THREADS)
        .build_global()
        .unwrap();

    let start = Instant::now();
    (0..NUM_THREADS).into_par_iter().for_each(|_| compute_hashes());
    let duration = start.elapsed();

    let total_hashes = NUM_HASHES * NUM_THREADS;
    let hashes_per_second = total_hashes as f64 / duration.as_secs_f64();
    println!("Time taken: {:?} seconds", duration);
    println!("Hash rate: {:.0} hashes per second", hashes_per_second);
}

Save it and you are done! To run it just execute it via cargo run --release in the same directory.


Thank you very much! It worked for my purposes!
3  Bitcoin / Development & Technical Discussion / Re: how many sha256 hashes can a consumer-grade CPU compute per second in average? on: October 26, 2023, 12:11:21 AM
I just made a script for this, that way op can verify how fast his PC can generate sha codes.

Code:
time for a in $(seq 1 10); do echo "$a" | sha256sum; done

The code is for linux and what it does is to generate 10 sha256 and print the time:

Quote
real   0m0.019s
user   0m0.015s
sys   0m0.008s

Now let's try with 1000 and see the time.

Quote
real   0m1.501s
user   0m1.413s
sys   0m0.570s

And with 10,000

Quote
real   0m16.384s
user   0m14.474s
sys   0m5.943s

And i get these results with this CPU, maybe other users could test and post their results with a better PC:

Code:
*-cpu
          product: Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
          vendor: Intel Corp.
          physical id: 1
          bus info: cpu@0
          version: 6.94.3
          size: 2660MHz
          capacity: 3200MHz
          width: 64 bits

Thanks for the code!

However, it understimates the computations because it runs shell commands each time. For every hash, the operating system will load the SHA256SUM binary into memory, make the proper system calls, then execute. There is a lot of CPU cycles there which are not used for computing the hashes.

I think it the proper way is to compute millions of hashes within a C or Rust program (maybe C++ too) and also measure the time within the program itself, using the languages libraries.

That's because running the `time` command line ulitiy also takes into account the time to load the program into memory, setup the main function, exit the program, which is a lot of system calls and numerous CPU cycles that are not used for the computation of the hashes and they do take some miliseconds.
4  Bitcoin / Development & Technical Discussion / Re: how many sha256 hashes can a consumer-grade CPU compute per second in average? on: October 25, 2023, 11:49:47 PM

Otherwise, could somebody help me write a C code or Rust code with threads to run the computations in a multicore computer? So I can test it locally.


Might could help you with that.

Can you give me infos about ur CPU that will be used for this test? Need to know so I can set the maximum of threads that will be used.
Otherwise I will just set two variables so you can adjust it while testing. One for the number of used threads and one for the amount of hashes per thread.
Rust is fine for you?

I have a linux machine, x86_64 architecture, 4-core Intel. Thank you!
5  Bitcoin / Development & Technical Discussion / how many sha256 hashes can a consumer-grade CPU compute per second in average? on: October 25, 2023, 06:30:20 PM
Is there a reliable source of information, maybe academic work or independent analysis with statistics, on the average number of sha256 hashes a consumer-grade CPU can compute?

Otherwise, could somebody help me write a C code or Rust code with threads to run the computations in a multicore computer? So I can test it locally.

I just would like to know a rough estimate. I'd like to know the order of magnitude, such as hundreds of thousands or maybe millions of hashes per second.
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!