Skip to content

Commit

Permalink
Update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Nov 30, 2023
1 parent 52c3b2b commit 0911877
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 52 deletions.
8 changes: 4 additions & 4 deletions benchmark/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

project : default-build release <link>static ;

exe buffer : buffer.cpp /boost//chrono ;
exe unordered : unordered.cpp /boost//chrono ;
exe average : average.cpp /boost//chrono ;
exe keys : keys.cpp /boost//chrono ;
exe buffer : buffer.cpp ;
exe unordered : unordered.cpp ;
exe average : average.cpp ;
exe keys : keys.cpp ;
14 changes: 7 additions & 7 deletions benchmark/average.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Copyright 2017, 2018 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>
Expand All @@ -11,8 +11,8 @@
#include <boost/hash2/murmur3.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/chrono.hpp>
#include <boost/core/demangle.hpp>
#include <boost/core/type_name.hpp>
#include <chrono>
#include <typeinfo>
#include <cstddef>
#include <cstdio>
Expand All @@ -22,7 +22,7 @@

template<class R, class H> void test_( int N )
{
typedef boost::chrono::steady_clock clock_type;
typedef std::chrono::steady_clock clock_type;

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

Expand All @@ -39,7 +39,7 @@ template<class R, class H> void test_( int N )

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

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

r /= N;

Expand All @@ -48,12 +48,12 @@ template<class R, class H> void test_( int N )

r /= stddev;

printf( "%s: r=%e, %lld ms\n", boost::core::demangle( typeid(H).name() ).c_str(), r, ms );
printf( "%s: r=%e, %lld ms\n", boost::core::type_name<H>().c_str(), r, ms );
}

template<class R> void test( int N )
{
printf( "Integral result type `%s`:\n\n", boost::core::demangle( typeid(R).name() ).c_str() );
printf( "Integral result type `%s`:\n\n", boost::core::type_name<R>().c_str() );

test_<R, boost::hash2::fnv1a_32>( N );
test_<R, boost::hash2::fnv1a_64>( N );
Expand Down
16 changes: 10 additions & 6 deletions benchmark/buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include <boost/hash2/fnv1a.hpp>
// 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/spooky2.hpp>
Expand All @@ -7,8 +11,8 @@
#include <boost/hash2/sha1.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/chrono.hpp>
#include <boost/core/demangle.hpp>
#include <boost/core/type_name.hpp>
#include <chrono>
#include <vector>
#include <cstdio>
#include <typeinfo>
Expand All @@ -17,7 +21,7 @@ template<class H> void test_( unsigned char const * p, int N, int M )
{
H h;

typedef boost::chrono::steady_clock clock_type;
typedef std::chrono::steady_clock clock_type;

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

Expand All @@ -28,12 +32,12 @@ template<class H> void test_( unsigned char const * p, int N, int M )

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

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

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

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

extern unsigned char data[];
Expand Down
18 changes: 9 additions & 9 deletions benchmark/keys.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Copyright 2017-2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#define _CRT_SECURE_NO_WARNINGS

Expand All @@ -13,10 +13,10 @@
#include <boost/hash2/murmur3.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/chrono.hpp>
#include <boost/core/demangle.hpp>
#include <boost/config.hpp>
#include <boost/core/type_name.hpp>
#include <boost/cstdint.hpp>
#include <chrono>
#include <random>
#include <typeinfo>
#include <cstddef>
#include <cstdio>
Expand Down Expand Up @@ -252,7 +252,7 @@ template<class H> class hasher4

template<class H, class V> void test3( int N, V const& v, std::size_t seed )
{
typedef boost::chrono::steady_clock clock_type;
typedef std::chrono::steady_clock clock_type;

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

Expand All @@ -267,9 +267,9 @@ template<class H, class V> void test3( int N, V const& v, std::size_t seed )

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

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

std::string hash = boost::core::demangle( typeid(H).name() );
std::string hash = boost::core::type_name<H>();

#if defined( _MSC_VER )

Expand Down Expand Up @@ -300,7 +300,7 @@ int main()
{
v.reserve( N );

boost::mt19937_64 rnd;
std::mt19937_64 rnd;

for( int i = 0; i < N; ++i )
{
Expand Down
41 changes: 15 additions & 26 deletions benchmark/unordered.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Copyright 2017-2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#define _CRT_SECURE_NO_WARNINGS

Expand All @@ -13,11 +13,11 @@
#include <boost/hash2/murmur3.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/unordered_set.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/chrono.hpp>
#include <boost/core/demangle.hpp>
#include <boost/config.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
#include <boost/core/type_name.hpp>
#include <boost/cstdint.hpp>
#include <random>
#include <chrono>
#include <typeinfo>
#include <cstddef>
#include <cstdio>
Expand Down Expand Up @@ -210,7 +210,7 @@ template<class H> class hasher4

template<class V, class S> void test4( int N, V const& v, char const * hash, S s )
{
typedef boost::chrono::steady_clock clock_type;
typedef std::chrono::steady_clock clock_type;

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

Expand All @@ -230,37 +230,26 @@ template<class V, class S> void test4( int N, V const& v, char const * hash, S s

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

long long ms1 = boost::chrono::duration_cast<boost::chrono::milliseconds>( t2 - t1 ).count();
long long ms2 = boost::chrono::duration_cast<boost::chrono::milliseconds>( t3 - t2 ).count();
long long ms1 = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
long long ms2 = std::chrono::duration_cast<std::chrono::milliseconds>( t3 - t2 ).count();

std::size_t n = s.bucket_count();
std::size_t m = 0;

for( std::size_t i = 0; i < n; ++i )
{
std::size_t k = s.bucket_size( i );

if( k > m )
{
m = k;
}
}

#if defined( _MSC_VER )

std::printf( "%s: n=%Iu, m=%Iu, q=%Iu, %lld + %lld ms\n", hash, n, m, q, ms1, ms2 );
std::printf( "%s: n=%Iu, q=%Iu, %lld + %lld ms\n", hash, n, q, ms1, ms2 );

#else

std::printf( "%s: n=%zu, m=%zu, q=%zu, %lld + %lld ms\n", hash, n, m, q, ms1, ms2 );
std::printf( "%s: n=%zu, q=%zu, %lld + %lld ms\n", hash, n, q, ms1, ms2 );

#endif
}

template<class K, class H, class V> void test3( int N, V const& v, std::size_t seed )
{
boost::unordered_set<K, H> s( 0, H( seed ) );
test4( N, v, boost::core::demangle( typeid(H).name() ).c_str(), s );
boost::unordered_flat_set<K, H> s( 0, H( seed ) );
test4( N, v, boost::core::type_name<H>().c_str(), s );
}

template<class K, class H, class V> void test2( int N, V const& v )
Expand All @@ -281,7 +270,7 @@ int main()
{
v.reserve( N * 16 );

boost::mt19937_64 rnd;
std::mt19937_64 rnd;

for( int i = 0; i < 16 * N; ++i )
{
Expand All @@ -305,7 +294,7 @@ int main()
typedef std::string K;

{
boost::unordered_set<K> s;
boost::unordered_flat_set<K> s;
test4( N, v, "default", s );
std::puts( "" );
}
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ run integral_result.cpp ;
compile ../benchmark/buffer.cpp ;
compile ../benchmark/unordered.cpp ;
compile ../benchmark/average.cpp ;
compile ../benchmark/keys.cpp ;

0 comments on commit 0911877

Please sign in to comment.