Initial commit loop_time_test.cpp and its infrastructure.

This commit is contained in:
Beman
2013-05-27 07:44:29 -04:00
parent 7f9d91e6d2
commit 32b04869e8
3 changed files with 306 additions and 0 deletions

208
test/loop_time_test.cpp Normal file
View File

@ -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 <boost/endian/detail/disable_warnings.hpp>
#include <boost/endian/conversion.hpp>
#include <boost/endian/types.hpp>
#include <boost/cstdint.hpp>
#include <boost/timer/timer.hpp>
#include <iostream>
#include <cstdlib>
#include <boost/detail/lightweight_main.hpp>
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 <class T, class EndianT>
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<T>(i);
}
t.stop();
cout << "x: " << x << endl;
cout << "<td align=\"right\">" << t.format(places, "%t") << " s</td>";
}
{
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<T>(i);
}
big_endian(x);
t.stop();
big_endian(x);
cout << "x: " << x << endl;
cout << "<td align=\"right\">" << t.format(places, "%t") << " s</td>";
}
}
//void test_big_int16()
//{
// cout << "<tr><td>16-bit aligned big endian</td>";
// time<int16_t, big_int16_t>(user::return_x_big_int16);
// time<int16_t, big_int16_t>(user::return_x_value_big_int16);
// time<int16_t, big_int16_t>(user::return_x_in_place_big_int16);
// time<int16_t, big_int16_t>(user::return_x_big_int16);
// cout << "</tr>\n";
//}
//void test_little_int16()
//{
// cout << "<tr><td>16-bit aligned little endian</td>";
// time<int16_t, little_int16_t>(user::return_x_little_int16);
// time<int16_t, little_int16_t>(user::return_x_value_little_int16);
// time<int16_t, little_int16_t>(user::return_x_in_place_little_int16);
// time<int16_t, little_int16_t>(user::return_x_little_int16);
// cout << "</tr>\n";
//}
void test_big_int32()
{
cout << "<tr><td>32-bit aligned big endian</td>";
time<int32_t, big_int32_t>();
cout << "</tr>\n";
}
void test_little_int32()
{
cout << "<tr><td>32-bit aligned little endian</td>";
time<int32_t, little_int32_t>();
cout << "</tr>\n";
}
//void test_big_int64()
//{
// cout << "<tr><td>64-bit aligned big endian</td>";
// time<int64_t, big_int64_t>(user::return_x_big_int64);
// time<int64_t, big_int64_t>(user::return_x_value_big_int64);
// time<int64_t, big_int64_t>(user::return_x_in_place_big_int64);
// time<int64_t, big_int64_t>(user::return_x_big_int64);
// cout << "</tr>\n";
//}
//void test_little_int64()
//{
// cout << "<tr><td>64-bit aligned little endian</td>";
// time<int64_t, little_int64_t>(user::return_x_little_int64);
// time<int64_t, little_int64_t>(user::return_x_value_little_int64);
// time<int64_t, little_int64_t>(user::return_x_in_place_little_int64);
// time<int64_t, little_int64_t>(user::return_x_little_int64);
// cout << "</tr>\n";
//}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
int cpp_main(int argc, char* argv[])
{
process_command_line(argc, argv);
cout
<< "<html>\n<head>\n<title>Endian Speed Test</title>\n</head>\n<body>\n"
<< "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\""
<< "style=\"border-collapse: collapse\" bordercolor=\"#111111\">\n"
<< "<tr><td colspan=\"6\" align=\"center\"><b>"
<< BOOST_COMPILER << "</b></td></tr>\n"
<< "<tr><td colspan=\"6\" align=\"center\"><b>"
<< " Iterations: " << n
<< ", Intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG
<< "</b></td></tr>\n"
<< "<tr><td><b>Test Case</b></td>\n"
"<td align=\"center\"><b>int<br>arg</b></td>\n"
"<td align=\"center\"><b>int<br>value(arg)</b></td>\n"
"<td align=\"center\"><b>int<br>in place(arg)</b></td>\n"
"<td align=\"center\"><b>Endian<br>arg</b></td>\n"
"</tr>\n"
;
//test_big_int16();
//test_little_int16();
test_big_int32();
test_little_int32();
//test_big_int64();
//test_little_int64();
cout << "\n</table>\n</body>\n</html>\n";
return 0;
}
#include <boost/endian/detail/disable_warnings_pop.hpp>

View File

@ -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

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{541A2D06-B34E-4592-BE47-F87DF47E73D8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>loop_time_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>"$(TargetDir)\$(TargetName).exe" 1000</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>"$(TargetDir)\$(TargetName).exe" 1000000000</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\loop_time_test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>