Added comparison to boost::pool memory allocator.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@325 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
b8142d7acc
commit
b078e019be
3 changed files with 471 additions and 19 deletions
119
test/SmallObj/CompareSmallObj.dev
Normal file
119
test/SmallObj/CompareSmallObj.dev
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
[Project]
|
||||||
|
FileName=CompareSmallObj.dev
|
||||||
|
Name=CompareSmallObj
|
||||||
|
UnitCount=7
|
||||||
|
Type=1
|
||||||
|
Ver=1
|
||||||
|
ObjFiles=
|
||||||
|
Includes=C:\Projects\loki\include\loki;C:\Projects\boost_1_33_0
|
||||||
|
Libs=
|
||||||
|
PrivateResource=
|
||||||
|
ResourceIncludes=
|
||||||
|
MakeIncludes=
|
||||||
|
Compiler=
|
||||||
|
CppCompiler=-D LOKI_SMALL_OBJECT_USE_NEW_ARRAY_@@_-D COMPARE_BOOST_POOL_@@_
|
||||||
|
Linker=
|
||||||
|
IsCpp=1
|
||||||
|
Icon=
|
||||||
|
ExeOutput=
|
||||||
|
ObjectOutput=
|
||||||
|
OverrideOutput=0
|
||||||
|
OverrideOutputName=CompareSmallObj.exe
|
||||||
|
HostApplication=
|
||||||
|
Folders=Headers,Sources
|
||||||
|
CommandLine=
|
||||||
|
UseCustomMakefile=0
|
||||||
|
CustomMakefile=
|
||||||
|
IncludeVersionInfo=0
|
||||||
|
SupportXPThemes=0
|
||||||
|
CompilerSet=0
|
||||||
|
CompilerSettings=0000001001001000000000
|
||||||
|
|
||||||
|
[Unit1]
|
||||||
|
FileName=timer.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Headers
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit2]
|
||||||
|
FileName=SmallObjBench.cpp
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Sources
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit3]
|
||||||
|
FileName=..\..\include\loki\Threads.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Headers
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit4]
|
||||||
|
FileName=..\..\include\loki\Singleton.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Headers
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit5]
|
||||||
|
FileName=..\..\include\loki\SmallObj.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Headers
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit6]
|
||||||
|
FileName=..\..\src\Singleton.cpp
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Sources
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit7]
|
||||||
|
FileName=..\..\src\SmallObj.cpp
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Sources
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[VersionInfo]
|
||||||
|
Major=0
|
||||||
|
Minor=1
|
||||||
|
Release=1
|
||||||
|
Build=1
|
||||||
|
LanguageID=1033
|
||||||
|
CharsetID=1252
|
||||||
|
CompanyName=
|
||||||
|
FileVersion=
|
||||||
|
FileDescription=Developed using the Dev-C++ IDE
|
||||||
|
InternalName=
|
||||||
|
LegalCopyright=
|
||||||
|
LegalTrademarks=
|
||||||
|
OriginalFilename=
|
||||||
|
ProductName=
|
||||||
|
ProductVersion=
|
||||||
|
AutoIncBuildNr=0
|
||||||
|
|
235
test/SmallObj/CompareSmallObj.vcproj
Normal file
235
test/SmallObj/CompareSmallObj.vcproj
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="CompareSmallObj"
|
||||||
|
ProjectGUID="{0A98B714-818C-4DD3-A07C-BDD16399F362}"
|
||||||
|
Keyword="Win32Proj">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory="Debug"
|
||||||
|
IntermediateDirectory="Debug"
|
||||||
|
ConfigurationType="1"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
AdditionalIncludeDirectories="..\include;..\include\loki;..\..\..\boost_1_33_0\"
|
||||||
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;COMPARE_BOOST_POOL"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
MinimalRebuild="TRUE"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="5"
|
||||||
|
RuntimeTypeInfo="TRUE"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
WarningLevel="4"
|
||||||
|
Detect64BitPortabilityProblems="TRUE"
|
||||||
|
DebugInformationFormat="3"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="$(OutDir)/CompareSmallObj.exe"
|
||||||
|
LinkIncremental="2"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
ProgramDatabaseFile="$(OutDir)/test.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory="Release"
|
||||||
|
IntermediateDirectory="Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="..\include;..\include\loki;..\..\..\boost_1_33_0\"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;COMPARE_BOOST_POOL"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="4"
|
||||||
|
RuntimeTypeInfo="TRUE"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
WarningLevel="4"
|
||||||
|
Detect64BitPortabilityProblems="TRUE"
|
||||||
|
DebugInformationFormat="0"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="$(OutDir)/CompareSmallObj.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
SubSystem="1"
|
||||||
|
OptimizeReferences="2"
|
||||||
|
EnableCOMDATFolding="2"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||||
|
UniqueIdentifier="{D98BEADF-A77F-476b-BAA7-41B12B269FBF}">
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\src\Singleton.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\src\SmallObj.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\SmallObjBench.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../../include/loki"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\timer.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
|
UniqueIdentifier="{7DF39E90-C717-4886-A90C-D18708A77099}">
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\include\loki\Singleton.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\include\loki\SmallObj.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\include\loki\Threads.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Resource Files"
|
||||||
|
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
||||||
|
UniqueIdentifier="{DFC2006D-7B0E-48f3-907F-2433F0935110}">
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Boost_Pool"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\ct_gcd_lcm.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\gcd_lcm.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\guard.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\mutex.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\object_pool.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\pool.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\pool_alloc.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\pool_construct.inc">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\pool_construct_simple.inc">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\poolfwd.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\simple_segregated_storage.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\detail\singleton.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\boost_1_33_0\boost\pool\singleton_pool.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
|
@ -25,6 +25,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
#include <boost\pool\object_pool.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -44,12 +48,70 @@ struct Base<void> : public ThisIsASmallObject {};
|
||||||
|
|
||||||
typedef Base<void>
|
typedef Base<void>
|
||||||
A;
|
A;
|
||||||
typedef Base<Loki::SmallObject<> >
|
typedef Base< Loki::SmallObject< Loki::SingleThreaded > >
|
||||||
B;
|
B;
|
||||||
typedef Base<Loki::SmallValueObject<> >
|
typedef Base< Loki::SmallValueObject< Loki::SingleThreaded > >
|
||||||
C;
|
C;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
|
||||||
|
class BoostPoolNew
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static boost::object_pool< BoostPoolNew > BoostPool;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Throwing single-object new throws bad_alloc when allocation fails.
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/// @note MSVC complains about non-empty exception specification lists.
|
||||||
|
static void * operator new ( std::size_t )
|
||||||
|
#else
|
||||||
|
static void * operator new ( std::size_t ) throw ( std::bad_alloc )
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return BoostPool.malloc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Non-throwing single-object new returns NULL if allocation fails.
|
||||||
|
static void * operator new ( std::size_t, const std::nothrow_t & ) throw ()
|
||||||
|
{
|
||||||
|
return BoostPool.malloc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placement single-object new merely calls global placement new.
|
||||||
|
inline static void * operator new ( std::size_t size, void * place )
|
||||||
|
{
|
||||||
|
return ::operator new( size, place );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Single-object delete.
|
||||||
|
static void operator delete ( void * p ) throw ()
|
||||||
|
{
|
||||||
|
BoostPool.free( reinterpret_cast< BoostPoolNew * >( p ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Non-throwing single-object delete is only called when nothrow
|
||||||
|
new operator is used, and the constructor throws an exception.
|
||||||
|
*/
|
||||||
|
static void operator delete ( void * p, const std::nothrow_t & ) throw()
|
||||||
|
{
|
||||||
|
BoostPool.free( reinterpret_cast< BoostPoolNew * >( p ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placement single-object delete merely calls global placement delete.
|
||||||
|
inline static void operator delete ( void * p, void * place )
|
||||||
|
{
|
||||||
|
::operator delete ( p, place );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
boost::object_pool< BoostPoolNew > BoostPoolNew::BoostPool;
|
||||||
|
|
||||||
|
typedef Base< BoostPoolNew > D;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class A
|
class A
|
||||||
{ int i; int* p;};
|
{ int i; int* p;};
|
||||||
|
@ -61,7 +123,7 @@ class C : public Loki::SmallValueObject<>
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_new_delete(int loop, Timer& t, char* s)
|
int run_new_delete(int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -77,7 +139,7 @@ int run_new_delete(int loop, Timer& t, char* s)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_new_delete(T** array, int N, int loop, Timer& t, char* s)
|
int run_new_delete(T** array, int N, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -94,7 +156,7 @@ int run_new_delete(T** array, int N, int loop, Timer& t, char* s)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_new(T** array, int loop, Timer& t, char* s)
|
int run_new(T** array, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -106,7 +168,7 @@ int run_new(T** array, int loop, Timer& t, char* s)
|
||||||
return t.t();
|
return t.t();
|
||||||
}
|
}
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_delete(T** array, int loop, Timer& t, char* s)
|
int run_delete(T** array, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -120,7 +182,7 @@ int run_delete(T** array, int loop, Timer& t, char* s)
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_new_delete_array(int N, int loop, Timer& t, char* s)
|
int run_new_delete_array(int N, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -136,7 +198,7 @@ int run_new_delete_array(int N, int loop, Timer& t, char* s)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_new_array( int N, T** array, int loop, Timer& t, char* s)
|
int run_new_array( int N, T** array, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -148,7 +210,7 @@ int run_new_array( int N, T** array, int loop, Timer& t, char* s)
|
||||||
return t.t();
|
return t.t();
|
||||||
}
|
}
|
||||||
template<class T>
|
template<class T>
|
||||||
int run_delete_array( T** array, int loop, Timer& t, char* s)
|
int run_delete_array( T** array, int loop, Timer& t, const char* s)
|
||||||
{
|
{
|
||||||
t.start();
|
t.start();
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
@ -163,21 +225,29 @@ int run_delete_array( T** array, int loop, Timer& t, char* s)
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int loop = 1000000
|
int loop = 1000000;
|
||||||
;
|
|
||||||
|
cout << "Small-Object Benchmark Tests" << endl;
|
||||||
std::cout << "\n";
|
cout << "A = global new and delete \tsizeof(A) =" << sizeof(A) << endl;
|
||||||
|
cout << "B = Loki::SmallObject \tsizeof(B) =" << sizeof(B) << endl;
|
||||||
|
cout << "C = Loki::SmallValueObject\tsizeof(C) =" << sizeof(C) << endl;
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
cout << "D = boost::object_pool \tsizeof(D) =" << sizeof(D) << endl;
|
||||||
|
#endif
|
||||||
|
cout << endl << endl;
|
||||||
|
|
||||||
Timer t;
|
Timer t;
|
||||||
|
|
||||||
t.t100 = 0;
|
t.t100 = 0;
|
||||||
t.t100 = run_new_delete<A>(loop,t,"new & delete A : ");
|
t.t100 = run_new_delete<A>(loop,t,"new & delete A : ");
|
||||||
run_new_delete<B>(loop,t,"new & delete B : ");
|
run_new_delete<B>(loop,t,"new & delete B : ");
|
||||||
run_new_delete<C>(loop,t,"new & delete C : ");
|
run_new_delete<C>(loop,t,"new & delete C : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_new_delete<D>(loop,t,"new & delete D : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
// Loki::AllocatorSingleton<>::ClearExtraMemory();
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int N = 100000;
|
int N = 100000;
|
||||||
|
@ -186,21 +256,29 @@ int main()
|
||||||
A** a = new A*[N];
|
A** a = new A*[N];
|
||||||
B** b = new B*[N];
|
B** b = new B*[N];
|
||||||
C** c = new C*[N];
|
C** c = new C*[N];
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
D** d = new D*[N];
|
||||||
|
#endif
|
||||||
|
|
||||||
for(int i=0; i<N; i++)
|
for(int i=0; i<N; i++)
|
||||||
{
|
{
|
||||||
a[i]=0;
|
a[i]=0;
|
||||||
b[i]=0;
|
b[i]=0;
|
||||||
c[i]=0;
|
c[i]=0;
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
d[i]=0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
t.t100 = 0;
|
t.t100 = 0;
|
||||||
t.t100 = run_new_delete(a,N,loop2,t,"new & del. A on array: ");
|
t.t100 = run_new_delete(a,N,loop2,t,"new & del. A on array: ");
|
||||||
run_new_delete(b,N,loop2,t,"new & del. B on array: ");
|
run_new_delete(b,N,loop2,t,"new & del. B on array: ");
|
||||||
run_new_delete(c,N,loop2,t,"new & del. C on array: ");
|
run_new_delete(c,N,loop2,t,"new & del. C on array: ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_new_delete(d,N,loop2,t,"new & del. D on array: ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
// Loki::AllocatorSingleton<>::ClearExtraMemory();
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,6 +286,9 @@ int main()
|
||||||
t.t100 = run_new(a,N,t,"new A on array : ");
|
t.t100 = run_new(a,N,t,"new A on array : ");
|
||||||
run_new(b,N,t,"new B on array : ");
|
run_new(b,N,t,"new B on array : ");
|
||||||
run_new(c,N,t,"new C on array : ");
|
run_new(c,N,t,"new C on array : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_new(d,N,t,"new D on array : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -216,9 +297,11 @@ int main()
|
||||||
t.t100 = run_delete(a,N,t,"delete A on array : ");
|
t.t100 = run_delete(a,N,t,"delete A on array : ");
|
||||||
run_delete(b,N,t,"delete B on array : ");
|
run_delete(b,N,t,"delete B on array : ");
|
||||||
run_delete(c,N,t,"delete C on array : ");
|
run_delete(c,N,t,"delete C on array : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_delete(d,N,t,"delete D on array : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
// Loki::AllocatorSingleton<>::ClearExtraMemory();
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -228,6 +311,9 @@ int main()
|
||||||
t.t100 = run_new_delete_array<A>(N,loop,t,"new & delete [] A : ");
|
t.t100 = run_new_delete_array<A>(N,loop,t,"new & delete [] A : ");
|
||||||
run_new_delete_array<B>(N,loop,t,"new & delete [] B : ");
|
run_new_delete_array<B>(N,loop,t,"new & delete [] B : ");
|
||||||
run_new_delete_array<C>(N,loop,t,"new & delete [] C : ");
|
run_new_delete_array<C>(N,loop,t,"new & delete [] C : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_new_delete_array<D>(N,loop,t,"new & delete [] D : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -238,6 +324,9 @@ int main()
|
||||||
t.t100 = run_new_array(N,a,count,t,"new [] A on array : ");
|
t.t100 = run_new_array(N,a,count,t,"new [] A on array : ");
|
||||||
run_new_array(N,b,count,t,"new [] B on array : ");
|
run_new_array(N,b,count,t,"new [] B on array : ");
|
||||||
run_new_array(N,c,count,t,"new [] C on array : ");
|
run_new_array(N,c,count,t,"new [] C on array : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_new_array(N,d,count,t,"new [] D on array : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -246,11 +335,17 @@ int main()
|
||||||
t.t100 = run_delete_array(a,count,t,"delete [] A on array : ");
|
t.t100 = run_delete_array(a,count,t,"delete [] A on array : ");
|
||||||
run_delete_array(b,count,t,"delete [] B on array : ");
|
run_delete_array(b,count,t,"delete [] B on array : ");
|
||||||
run_delete_array(c,count,t,"delete [] C on array : ");
|
run_delete_array(c,count,t,"delete [] C on array : ");
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
run_delete_array(d,count,t,"delete [] D on array : ");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
delete [] a;
|
delete [] a;
|
||||||
delete [] b;
|
delete [] b;
|
||||||
delete [] c;
|
delete [] c;
|
||||||
|
#ifdef COMPARE_BOOST_POOL
|
||||||
|
delete [] d;
|
||||||
|
#endif
|
||||||
|
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
Loki::AllocatorSingleton<>::ClearExtraMemory();
|
Loki::AllocatorSingleton<>::ClearExtraMemory();
|
||||||
|
@ -265,6 +360,9 @@ int main()
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.8 2005/10/26 00:41:00 rich_sposato
|
||||||
|
// Added comparison to boost::pool memory allocator.
|
||||||
|
//
|
||||||
// Revision 1.7 2005/10/14 18:35:06 rich_sposato
|
// Revision 1.7 2005/10/14 18:35:06 rich_sposato
|
||||||
// Added cvs keywords.
|
// Added cvs keywords.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue