From 32b04869e87d104700affe41d0c976e9d07e3d59 Mon Sep 17 00:00:00 2001 From: Beman Date: Mon, 27 May 2013 07:44:29 -0400 Subject: [PATCH] Initial commit loop_time_test.cpp and its infrastructure. --- test/loop_time_test.cpp | 208 ++++++++++++++++++ test/msvc2012/endian.sln | 6 + .../loop_time_test/loop_time_test.vcxproj | 92 ++++++++ 3 files changed, 306 insertions(+) create mode 100644 test/loop_time_test.cpp create mode 100644 test/msvc2012/loop_time_test/loop_time_test.vcxproj diff --git a/test/loop_time_test.cpp b/test/loop_time_test.cpp new file mode 100644 index 0000000..72783f1 --- /dev/null +++ b/test/loop_time_test.cpp @@ -0,0 +1,208 @@ +// loop_time_test.cpp ----------------------------------------------------------------// + +// Copyright Beman Dawes 2013 + +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +//--------------------------------------------------------------------------------------// + +#define _SCL_SECURE_NO_WARNINGS + +//#define BOOST_ENDIAN_NO_INTRINSICS +//#define BOOST_ENDIAN_LOG + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace boost; +using namespace boost::endian; + +using std::cout; +using std::endl; + +namespace +{ + typedef boost::timer::nanosecond_type nanosecond_t; + std::string command_args; + uint64_t n; // number of test cases to run + int places = 2; // decimal places for times + bool verbose (false); + + void process_command_line(int argc, char * argv[]) + { + for (int a = 0; a < argc; ++a) + { + command_args += argv[a]; + if (a != argc-1) + command_args += ' '; + } + + // cout << command_args << '\n';; + + if (argc >=2) +#ifndef _MSC_VER + n = std::atoll(argv[1]); +#else + n = _atoi64(argv[1]); +#endif + + for (; argc > 2; ++argv, --argc) + { + if ( *(argv[2]+1) == 'p' ) + places = atoi( argv[2]+2 ); + else if ( *(argv[2]+1) == 'v' ) + verbose = true; + else + { + cout << "Error - unknown option: " << argv[2] << "\n\n"; + argc = -1; + break; + } + } + + if (argc < 2) + { + cout << "Usage: loop_time_test n [Options]\n" + " The argument n specifies the number of test cases to run\n" + " Options:\n" + " -v Verbose messages\n" + " -p# Decimal places for times; default -p" << places << "\n"; + return std::exit(1); + } + } + +//--------------------------------------------------------------------------------------// + + template + void time() + { + { + cout << "*************Endian integer approach...\n"; + EndianT x(0); + boost::timer::cpu_timer t; + for (uint64_t i = 0; i < n; ++i) + { + x += static_cast(i); + } + t.stop(); + cout << "x: " << x << endl; + cout << "" << t.format(places, "%t") << " s"; + } + { + cout << "***************Endian conversion approach...\n"; + T x(0); + boost::timer::cpu_timer t; + big_endian(x); + for (uint64_t i = 0; i < n; ++i) + { + x += static_cast(i); + } + big_endian(x); + t.stop(); + big_endian(x); + cout << "x: " << x << endl; + cout << "" << t.format(places, "%t") << " s"; + } + } + + //void test_big_int16() + //{ + // cout << "16-bit aligned big endian"; + // time(user::return_x_big_int16); + // time(user::return_x_value_big_int16); + // time(user::return_x_in_place_big_int16); + // time(user::return_x_big_int16); + // cout << "\n"; + //} + + //void test_little_int16() + //{ + // cout << "16-bit aligned little endian"; + // time(user::return_x_little_int16); + // time(user::return_x_value_little_int16); + // time(user::return_x_in_place_little_int16); + // time(user::return_x_little_int16); + // cout << "\n"; + //} + + void test_big_int32() + { + cout << "32-bit aligned big endian"; + time(); + cout << "\n"; + } + + void test_little_int32() + { + cout << "32-bit aligned little endian"; + time(); + cout << "\n"; + } + + //void test_big_int64() + //{ + // cout << "64-bit aligned big endian"; + // time(user::return_x_big_int64); + // time(user::return_x_value_big_int64); + // time(user::return_x_in_place_big_int64); + // time(user::return_x_big_int64); + // cout << "\n"; + //} + + //void test_little_int64() + //{ + // cout << "64-bit aligned little endian"; + // time(user::return_x_little_int64); + // time(user::return_x_value_little_int64); + // time(user::return_x_in_place_little_int64); + // time(user::return_x_little_int64); + // cout << "\n"; + //} + +} // unnamed namespace + +//--------------------------------------------------------------------------------------// + +int cpp_main(int argc, char* argv[]) +{ + process_command_line(argc, argv); + + cout + << "\n\nEndian Speed Test\n\n\n" + << "\n" + << "\n" + << "\n" + << "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ; + + //test_big_int16(); + //test_little_int16(); + test_big_int32(); + test_little_int32(); + //test_big_int64(); + //test_little_int64(); + + cout << "\n
" + << BOOST_COMPILER << "
" + << " Iterations: " << n + << ", Intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG + << "
Test Caseint
arg
int
value(arg)
int
in place(arg)
Endian
arg
\n\n\n"; + + return 0; +} + +#include diff --git a/test/msvc2012/endian.sln b/test/msvc2012/endian.sln index 81590e0..066de40 100644 --- a/test/msvc2012/endian.sln +++ b/test/msvc2012/endian.sln @@ -21,6 +21,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udt_conversion_example", "u EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "speed_test", "speed_test\speed_test.vcxproj", "{5407AF29-59E9-4DE2-9939-F067576F7868}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loop_time_test", "loop_time_test\loop_time_test.vcxproj", "{541A2D06-B34E-4592-BE47-F87DF47E73D8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -65,6 +67,10 @@ Global {5407AF29-59E9-4DE2-9939-F067576F7868}.Debug|Win32.Build.0 = Debug|Win32 {5407AF29-59E9-4DE2-9939-F067576F7868}.Release|Win32.ActiveCfg = Release|Win32 {5407AF29-59E9-4DE2-9939-F067576F7868}.Release|Win32.Build.0 = Release|Win32 + {541A2D06-B34E-4592-BE47-F87DF47E73D8}.Debug|Win32.ActiveCfg = Debug|Win32 + {541A2D06-B34E-4592-BE47-F87DF47E73D8}.Debug|Win32.Build.0 = Debug|Win32 + {541A2D06-B34E-4592-BE47-F87DF47E73D8}.Release|Win32.ActiveCfg = Release|Win32 + {541A2D06-B34E-4592-BE47-F87DF47E73D8}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/msvc2012/loop_time_test/loop_time_test.vcxproj b/test/msvc2012/loop_time_test/loop_time_test.vcxproj new file mode 100644 index 0000000..32047e6 --- /dev/null +++ b/test/msvc2012/loop_time_test/loop_time_test.vcxproj @@ -0,0 +1,92 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {541A2D06-B34E-4592-BE47-F87DF47E73D8} + Win32Proj + loop_time_test + + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + "$(TargetDir)\$(TargetName).exe" 1000 + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + "$(TargetDir)\$(TargetName).exe" 1000000000 + + + + + + + + + \ No newline at end of file