~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to src/bench/crypto_hash.cpp

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2016 The Bitcoin Core developers
 
2
// Distributed under the MIT software license, see the accompanying
 
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
4
 
 
5
#include <iostream>
 
6
 
 
7
#include "bench.h"
 
8
#include "bloom.h"
 
9
#include "hash.h"
 
10
#include "uint256.h"
 
11
#include "utiltime.h"
 
12
#include "crypto/ripemd160.h"
 
13
#include "crypto/sha1.h"
 
14
#include "crypto/sha256.h"
 
15
#include "crypto/sha512.h"
 
16
 
 
17
/* Number of bytes to hash per iteration */
 
18
static const uint64_t BUFFER_SIZE = 1000*1000;
 
19
 
 
20
static void RIPEMD160(benchmark::State& state)
 
21
{
 
22
    uint8_t hash[CRIPEMD160::OUTPUT_SIZE];
 
23
    std::vector<uint8_t> in(BUFFER_SIZE,0);
 
24
    while (state.KeepRunning())
 
25
        CRIPEMD160().Write(begin_ptr(in), in.size()).Finalize(hash);
 
26
}
 
27
 
 
28
static void SHA1(benchmark::State& state)
 
29
{
 
30
    uint8_t hash[CSHA1::OUTPUT_SIZE];
 
31
    std::vector<uint8_t> in(BUFFER_SIZE,0);
 
32
    while (state.KeepRunning())
 
33
        CSHA1().Write(begin_ptr(in), in.size()).Finalize(hash);
 
34
}
 
35
 
 
36
static void SHA256(benchmark::State& state)
 
37
{
 
38
    uint8_t hash[CSHA256::OUTPUT_SIZE];
 
39
    std::vector<uint8_t> in(BUFFER_SIZE,0);
 
40
    while (state.KeepRunning())
 
41
        CSHA256().Write(begin_ptr(in), in.size()).Finalize(hash);
 
42
}
 
43
 
 
44
static void SHA256_32b(benchmark::State& state)
 
45
{
 
46
    std::vector<uint8_t> in(32,0);
 
47
    while (state.KeepRunning()) {
 
48
        for (int i = 0; i < 1000000; i++) {
 
49
            CSHA256().Write(begin_ptr(in), in.size()).Finalize(&in[0]);
 
50
        }
 
51
    }
 
52
}
 
53
 
 
54
static void SHA512(benchmark::State& state)
 
55
{
 
56
    uint8_t hash[CSHA512::OUTPUT_SIZE];
 
57
    std::vector<uint8_t> in(BUFFER_SIZE,0);
 
58
    while (state.KeepRunning())
 
59
        CSHA512().Write(begin_ptr(in), in.size()).Finalize(hash);
 
60
}
 
61
 
 
62
static void SipHash_32b(benchmark::State& state)
 
63
{
 
64
    uint256 x;
 
65
    while (state.KeepRunning()) {
 
66
        for (int i = 0; i < 1000000; i++) {
 
67
            *((uint64_t*)x.begin()) = SipHashUint256(0, i, x);
 
68
        }
 
69
    }
 
70
}
 
71
 
 
72
BENCHMARK(RIPEMD160);
 
73
BENCHMARK(SHA1);
 
74
BENCHMARK(SHA256);
 
75
BENCHMARK(SHA512);
 
76
 
 
77
BENCHMARK(SHA256_32b);
 
78
BENCHMARK(SipHash_32b);