Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2015 03:18
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rustyrussell/9c3c4bf3127419bd3f1d to your computer and use it in GitHub Desktop.
Simple bitcoin signature hashing benchmark code
/* Usage: benchmark-sha256 <numtxs> [<numiterations>]
* Benchmark the input signature hashes for a maximum-sized transaction with this many
* inputs
* Rusty Russell, <> GPLv3.
#include <ccan/crypto/sha256/sha256.c>
#include <ccan/time/time.h>
#include <stdio.h>
#include <string.h>
//#define BLOCKSIZE 1000000
#define BLOCKSIZE 8000000
int main(int argc, char *argv[])
struct timeabs start;
struct timerel diff;
size_t i, n, num_inputs = atoi(argv[1]);
union {
struct sha256 h;
char rest[BLOCKSIZE - 180 * num_inputs];
} block;
n = atoi(argv[2] ? argv[2] : "10000");
memset(&block, 0, sizeof(block));
sha256(&block.h, &n, sizeof(n));
start = time_now();
for (i = 0; i < n; i++) {
sha256(&block.h, &block, sizeof(block));
sha256(&block.h, &block.h, sizeof(block.h));
diff = time_divide(time_between(time_now(), start), n);
num_inputs, sizeof(block),
(unsigned long long)time_to_usec(time_multiply(diff, num_inputs)),
block.h.u.u8[0], block.h.u.u8[1], block.h.u.u8[2],
block.h.u.u8[3], block.h.u.u8[4], block.h.u.u8[5]);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment