diff --git a/test/msvc2012/benchmark/benchmark.vcxproj b/test/msvc2012/benchmark/benchmark.vcxproj index 814bf2c..51fcd8e 100644 --- a/test/msvc2012/benchmark/benchmark.vcxproj +++ b/test/msvc2012/benchmark/benchmark.vcxproj @@ -64,7 +64,7 @@ true - "$(TargetDir)\$(TargetName).exe" 10 + "$(TargetDir)\$(TargetName).exe" 10 -v Executing test... @@ -87,7 +87,7 @@ true - "$(TargetDir)\$(TargetName).exe" 10000 + "$(TargetDir)\$(TargetName).exe" 10000 -v Executing test... diff --git a/test/msvc2012/speed_test/speed_test.vcxproj b/test/msvc2012/speed_test/speed_test.vcxproj index 2a383e1..3ee2b16 100644 --- a/test/msvc2012/speed_test/speed_test.vcxproj +++ b/test/msvc2012/speed_test/speed_test.vcxproj @@ -34,9 +34,11 @@ + + diff --git a/test/speed_test.cpp b/test/speed_test.cpp index e69de29..67f11ce 100644 --- a/test/speed_test.cpp +++ b/test/speed_test.cpp @@ -0,0 +1,137 @@ +// speed_test.cpp --------------------------------------------------------------------// + +// Copyright Beman Dawes 2013 + +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +//--------------------------------------------------------------------------------------// + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace boost::endian; +using namespace boost::chrono; + +using std::cout; +using std::endl; +using boost::int16_t; +using boost::uint16_t; +using boost::int32_t; +using boost::uint32_t; +using boost::int64_t; +using boost::uint64_t; + +namespace +{ + long default_length(1); + steady_clock::duration length = seconds(default_length); + + template + uint32_t test(T x) + { + uint32_t count = 0; + T y = x; + steady_clock::time_point start = steady_clock::now(); + steady_clock::time_point end = start + length; + while (steady_clock::now() < end) + { + ++count; + reverse(y); + ++y; + reverse(y); + } + + cout << " loop executed " << count << " times" << endl; +// cout << " x is 0x" << std::hex << x << std::dec << endl; + + count = 0; + //Endian z(x); + Endian z; + start = steady_clock::now(); + end = start + length; + while (steady_clock::now() < end) + { + ++count; + ++z; + } + + cout << " loop executed " << count << " times" << endl; + + return count; + } + + uint32_t nop_test() + { + uint32_t count = 0; + steady_clock::time_point start = steady_clock::now(); + steady_clock::time_point end = start + length; + while (steady_clock::now() < end) + { + ++count; + } + + cout << " loop executed " << count << " times" << endl; + + return count; + } + + +} // unnamed namespace + +//--------------------------------------------------------------------------------------// + +int cpp_main(int argc, char* argv[]) +{ + if (argc > 1) + length = seconds(atol(argv[1])); + else + { + cout << "Invoke: speed_test [s]\n" + " where s is the number of seconds each test will be run (default " + << default_length << (default_length <= 1 ? " second)" : " seconds)") << endl; + } + + cout << "\nbyte swap intrinsics used: " BOOST_ENDIAN_INTRINSIC_MSG << endl << endl; + + //std::cerr << std::hex; + + cout << "nop" << endl; + nop_test(); + + + cout << "int16_t, big16_t" << endl; + test(0x1122); + + cout << "uint16_t" << endl; + test(0x1122U); + + cout << "int32_t, big32_t" << endl; + test(0x11223344); + + cout << "uint32_t, ubig32_t" << endl; + test(0x11223344UL); + + cout << "int64_t, big64_t" << endl; + test(0x1122334455667788); + + cout << "uint64_t, ubig64_t" << endl; + test(0x1122334455667788ULL); + + //cout << "float" << endl; + //test(1.2345f); + + //cout << "double" << endl; + //test(1.23456789); + + return 0; +} + +#include