File: buffer.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (89 lines) | stat: -rw-r--r-- 2,357 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2017-2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/fnv1a.hpp>
#include <boost/hash2/siphash.hpp>
#include <boost/hash2/xxhash.hpp>
#include <boost/hash2/xxh3.hpp>
#include <boost/hash2/md5.hpp>
#include <boost/hash2/sha1.hpp>
#include <boost/hash2/sha2.hpp>
#include <boost/hash2/sha3.hpp>
#include <boost/hash2/ripemd.hpp>
#include <boost/hash2/blake2.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/core/type_name.hpp>
#include <chrono>
#include <vector>
#include <cstdio>
#include <typeinfo>

template<class Hash> void test_( unsigned char const * p, int N, int M )
{
    Hash h;

    typedef std::chrono::steady_clock clock_type;

    clock_type::time_point t1 = clock_type::now();

    for( int i = 0; i < M; ++i )
    {
        boost::hash2::hash_append_range( h, {}, p, p + N );
    }

    clock_type::time_point t2 = clock_type::now();

    long long ms = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    unsigned r = boost::hash2::get_integral_result<unsigned>( h );

    std::printf( "%s (N=%d): %u: %lld ms, %.2f MB/s\n", boost::core::type_name<Hash>().c_str(), N, r, ms, 1000.0 * N * M / ms / 1048576 );
}

extern unsigned char data[];

void test( int N, int M )
{
    using namespace boost::hash2;

    test_<fnv1a_32>( data, N, M );
    test_<fnv1a_64>( data, N, M );
    test_<xxhash_32>( data, N, M );
    test_<xxhash_64>( data, N, M );
    test_<xxh3_128>( data, N, M );
    test_<siphash_32>( data, N, M );
    test_<siphash_64>( data, N, M );
    test_<md5_128>( data, N, M );
    test_<sha1_160>( data, N, M );
    test_<sha2_256>( data, N, M );
    test_<sha2_512>( data, N, M );
    test_<ripemd_160>( data, N, M );
    test_<ripemd_128>( data, N, M );
    test_<sha3_256>( data, N, M );
    test_<sha3_512>( data, N, M );
    test_<shake_128>( data, N, M );
    test_<blake2b_512>( data, N, M );
    test_<blake2s_256>( data, N, M );

    puts( "--" );
}

unsigned const N1 = 65536;
unsigned const M1 = 65535;

unsigned const N2 = 15;
unsigned const M2 = M1 * N1 / N2;

unsigned const N3 = 4;
unsigned const M3 = M1 * N1 / N3;

int main()
{
    test( N1, M1 );
    test( N2, M2 );
    test( N3, M3 );
}

unsigned char data[ N1 ];