replace tabs space

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@334 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-10-30 14:03:23 +00:00
parent 570f0ed652
commit 7fe4c81ff0
28 changed files with 799 additions and 778 deletions

View file

@ -66,7 +66,7 @@ typedef SingletonHolder
#ifndef USE_SEQUENCE
Factory< AbstractProduct, int, LOKI_TYPELIST_2( int, int ) >
#else
Factory< AbstractProduct, int, Seq< int, int > >
Factory< AbstractProduct, int, Seq< int, int > >
#endif
>
PFactory;
@ -163,7 +163,7 @@ SingletonHolder
#ifndef USE_SEQUENCE
Factory< AbstractProduct, int,LOKI_TYPELIST_3(CreateFunctor,int,int) >
#else
Factory< AbstractProduct, int,Seq<CreateFunctor,int,int> >
Factory< AbstractProduct, int,Seq<CreateFunctor,int,int> >
#endif
>
PFactoryFunctorParm;
@ -249,6 +249,9 @@ int main(int argc, char *argv[])
}
// $Log$
// Revision 1.5 2005/10/30 14:03:23 syntheticpp
// replace tabs space
//
// Revision 1.4 2005/10/30 13:49:44 syntheticpp
// make disabling the TYPELIST macros possible
//

View file

@ -1,9 +1,9 @@
// Boost.Function library
// Copyright Douglas Gregor 2001-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Copyright Douglas Gregor 2001-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// For more information, see http://www.boost.org
@ -44,20 +44,20 @@ struct write_three_obj{int operator()() const {global_int = 3; return 7;}};
struct write_three_obj{void operator()() const {global_int = 3;}};
#endif
static void write_five() {global_int = 5;}
static void write_three() {global_int = 3;}
struct generate_five_obj {int operator()() const {return 5;}};
struct generate_three_obj {int operator()() const {return 3;}};
static int generate_five() {return 5;}
static int generate_three() {return 3;}
static void write_five() {global_int = 5;}
static void write_three() {global_int = 3;}
struct generate_five_obj {int operator()() const {return 5;}};
struct generate_three_obj {int operator()() const {return 3;}};
static int generate_five() {return 5;}
static int generate_three() {return 3;}
static string identity_str(const string& s){return s;}
static string string_cat(const string& s1, const string& s2){return s1+s2;}
static int sum_ints(int x, int y){return x+y;}
struct write_const_1_nonconst_2
{
void operator()(){global_int = 2;}
void operator()() const {global_int = 1;}
void operator()(){global_int = 2;}
void operator()() const {global_int = 1;}
};
struct add_to_obj
{
@ -645,7 +645,7 @@ static void test_member_functions()
Loki::Function<int ()> f1_2(&one,&X::twice);
BOOST_CHECK(f1_2() == 2);
f1_2 = Loki::function<int ()>(&five,&X::twice);
f1_2 = Loki::function<int ()>(&five,&X::twice);
BOOST_CHECK(f1_2() == 10);
#endif
@ -698,12 +698,12 @@ static void test_ref()
try
{
#ifndef TEST_LOKI_FUNCTION
boost::function<int (int, int)> f(ref(atc));
BOOST_CHECK(f(1, 3) == 4);
boost::function<int (int, int)> f(ref(atc));
BOOST_CHECK(f(1, 3) == 4);
#else
//TODO: implement Loki::Ref
//Loki::Function<int (int, int)> f(Loki::ref(atc));
//BOOST_CHECK(f(1, 3) == 4);
//TODO: implement Loki::Ref
//Loki::Function<int (int, int)> f(Loki::ref(atc));
//BOOST_CHECK(f(1, 3) == 4);
#endif
}
@ -731,7 +731,7 @@ static void test_exception()
#else
catch(Loki::bad_function_call)
#endif
{
{
// okay
}
}

View file

@ -6,35 +6,35 @@
struct L1
{
L1(){std::cout << "create L1: " << this << "\n";}
~L1(){std::cout << "delete L1: " << this <<" \n";}
L1(){std::cout << "create L1: " << this << "\n";}
~L1(){std::cout << "delete L1: " << this <<" \n";}
};
struct L2
{
L2(){std::cout << "create L2 \n";}
~L2(){std::cout << "delete L2 \n";}
L2(){std::cout << "create L2 \n";}
~L2(){std::cout << "delete L2 \n";}
};
struct L3
{
L3(){std::cout << "create L3 \n";}
~L3(){std::cout << "delete L3 \n";}
L3(){std::cout << "create L3 \n";}
~L3(){std::cout << "delete L3 \n";}
};
int main()
{
Loki::SetLongevity
(new L1, 1);
Loki::SetLongevity<L1, void (*)(L1*)>
(new L1, 1, Loki::Private::Deleter<L1>::Delete);
Loki::SetLongevity<L1, Loki::Private::Deleter<L1>::Type>
(new L1, 1, Loki::Private::Deleter<L1>::Delete);
Loki::SetLongevity(new L2, 2);
Loki::SetLongevity(new L1, 1);
Loki::SetLongevity(new L3, 3);
Loki::SetLongevity(new L1, 1);
Loki::SetLongevity
(new L1, 1);
Loki::SetLongevity<L1, void (*)(L1*)>
(new L1, 1, Loki::Private::Deleter<L1>::Delete);
Loki::SetLongevity<L1, Loki::Private::Deleter<L1>::Type>
(new L1, 1, Loki::Private::Deleter<L1>::Delete);
Loki::SetLongevity(new L2, 2);
Loki::SetLongevity(new L1, 1);
Loki::SetLongevity(new L3, 3);
Loki::SetLongevity(new L1, 1);
std::cout << "\n";
std::cout << "\n";
}

View file

@ -27,32 +27,32 @@
struct L1
{
L1(){std::cout << "create L1: " << this << "\n";}
~L1(){std::cout << "delete L1: " << this <<" \n";}
L1(){std::cout << "create L1: " << this << "\n";}
~L1(){std::cout << "delete L1: " << this <<" \n";}
};
struct L2
{
L2(){std::cout << "create L2 \n";}
~L2(){std::cout << "delete L2 \n";}
L2(){std::cout << "create L2 \n";}
~L2(){std::cout << "delete L2 \n";}
};
struct M1
{
M1(){std::cout << "create M1 \n";}
~M1(){std::cout << "delete M1 \n";}
M1(){std::cout << "create M1 \n";}
~M1(){std::cout << "delete M1 \n";}
};
struct M2
{
M2(){std::cout << "create M2 \n";}
~M2(){std::cout << "delete M2 \n";}
M2(){std::cout << "create M2 \n";}
~M2(){std::cout << "delete M2 \n";}
};
int f()
{
std::cout << "f called \n";
return 0;
std::cout << "f called \n";
return 0;
}
std::string func();
@ -62,8 +62,8 @@ std::string func();
struct MemberTest
{
static Loki::OrderedStatic<1,M1> m1;
static Loki::OrderedStatic<2,M2> m2;
static Loki::OrderedStatic<1,M1> m1;
static Loki::OrderedStatic<2,M2> m2;
};
Loki::OrderedStatic<1,M1> MemberTest::m1;
Loki::OrderedStatic<2,M2> MemberTest::m2;
@ -72,8 +72,8 @@ Loki::OrderedStatic<2,M2> MemberTest::m2;
Loki::OrderedStatic<1,L1> l1;
Loki::OrderedStatic<2,L2> l2;
Loki::OrderedStatic<1, std::string, std::string(*)() > s1( &func );
Loki::OrderedStatic<2, std::string, Loki::Seq<char *> > s2( "s2" );
Loki::OrderedStatic<1, std::string, std::string(*)() > s1( &func );
Loki::OrderedStatic<2, std::string, Loki::Seq<char *> > s2( "s2" );
Loki::OrderedStatic<1, Loki::Functor<int>, Loki::Seq<int(*)()> > f1(f);
@ -81,8 +81,8 @@ Loki::OrderedStatic<1, Loki::Functor<int>, Loki::Seq<int(*)()> > f1(f);
struct MemberTest
{
static M1 m1;
static M2 m2;
static M1 m1;
static M2 m2;
};
M1 MemberTest::m1;
M2 MemberTest::m2;
@ -101,42 +101,42 @@ Loki::Functor<int> f1(f);
std::string func()
{
#ifdef TEST_ORDERED_STATIC
return *s2;
return *s2;
#else
return s2;
return s2;
#endif
}
int main()
{
{
#ifdef TEST_ORDERED_STATIC
Loki::OrderedStaticManager::Instance().createObjects();
std::cout << "\n";
Loki::OrderedStaticManager::Instance().createObjects();
std::cout << "\n";
(*f1)();
(*f1)();
std::cout << "value of s1: " << (*s1).c_str() << "\n";
std::cout << "value of s2: " << (*s2).c_str() << "\n";
std::string s("text11");
*s1=s;
std::cout << "value of s1: " << (*s1).c_str() << "\n";
std::cout << "value of s1: " << (*s1).c_str() << "\n";
std::cout << "value of s2: " << (*s2).c_str() << "\n";
std::string s("text11");
*s1=s;
std::cout << "value of s1: " << (*s1).c_str() << "\n";
#else
std::cout << "\n";
f1();
std::cout << "s1 = " << s1.c_str() << "\n";
std::cout << "s2 = " << s2.c_str() << "\n";
std::cout << "\n";
f1();
std::cout << "s1 = " << s1.c_str() << "\n";
std::cout << "s2 = " << s2.c_str() << "\n";
#endif
std::cout << "\n";
return 0;
std::cout << "\n";
return 0;
}

View file

@ -39,18 +39,18 @@ public:
#ifndef LOKI_DISABLE_TYPELIST_MACROS
Functor<void,LOKI_TYPELIST_1(bool &)> function(testFunction);
Functor<void,LOKI_TYPELIST_1(bool &)> function(testFunction);
Functor<void,LOKI_TYPELIST_1(bool &)> functor(testFunctor);
Functor<void,LOKI_TYPELIST_1(bool &)> classFunctor(&testClass,&TestClass::member);
Functor<void,LOKI_TYPELIST_1(bool &)> functorCopy(function);
Functor<void,NullType> bindFunctor(BindFirst(function,testResult));
Functor<void> chainFunctor(Chain(bindFunctor,bindFunctor));
#else
Functor<void,Seq<bool &> > function(testFunction);
Functor<void,Seq<bool &> > function(testFunction);
Functor<void,Seq<bool &> > functor(testFunctor);
Functor<void,Seq<bool &> > classFunctor(&testClass,&TestClass::member);
Functor<void,Seq<bool &> > functorCopy(function);
//TODO:
//TODO:
//Functor<void,NullType> bindFunctor(BindFirst(function,testResult));
//Functor<void> chainFunctor(Chain(bindFunctor,bindFunctor));
#endif
@ -83,8 +83,8 @@ public:
r=functionResult && functorResult && classFunctorResult && functorCopyResult && bindFunctorResult &&
chainFunctorResult;
#else
//TODO!
r=functionResult && functorResult && classFunctorResult && functorCopyResult;
//TODO!
r=functionResult && functorResult && classFunctorResult && functorCopyResult;
#endif
testAssert("Functor",r,result);

View file

@ -33,7 +33,7 @@ public:
using namespace Loki;
using namespace Loki::TL;
typedef Seq<char>::Type CharList;
typedef Seq<char>::Type CharList;
typedef Seq<char,int,double>::Type CharIntDoubleList;
typedef Seq<char,int,double,char>::Type CharIntDoubleCharList;
typedef Seq<Base,Derived1,Derived2>::Type BaseDerived1Derived2List;

View file

@ -162,12 +162,12 @@ private:
} smallObjectTest;
#ifndef SMALLOBJ_CPP
# define SMALLOBJ_CPP
# ifdef LOKI_NONCC
# include "../../include/noncc/loki/SmallObj.cpp"
# else
# include "../../src/SmallObj.cpp"
# endif
# define SMALLOBJ_CPP
# ifdef LOKI_NONCC
# include "../../include/noncc/loki/SmallObj.cpp"
# else
# include "../../src/SmallObj.cpp"
# endif
#endif

View file

@ -19,44 +19,44 @@
namespace ThreadsTestPrivate
{
class SingleLevel : public Loki::SingleThreaded<SingleLevel>
{
int i;
public:
void test()
{
Lock lock0;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
class SingleLevel : public Loki::SingleThreaded<SingleLevel>
{
int i;
public:
void test()
{
Lock lock0;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
class ClassLevel : public Loki::ClassLevelLockable<ClassLevel>
{
int i;
public:
void test()
{
Lock lock0;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
class ClassLevel : public Loki::ClassLevelLockable<ClassLevel>
{
int i;
public:
void test()
{
Lock lock0;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
class ObjectLevel : public Loki::ObjectLevelLockable<ObjectLevel>
{
int i;
public:
void test()
{
//Lock lock0_must_not_compile;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
class ObjectLevel : public Loki::ObjectLevelLockable<ObjectLevel>
{
int i;
public:
void test()
{
//Lock lock0_must_not_compile;
Lock lock(*this);
Lock lockThis(this);
i++;
}
};
}
class ThreadsTest : public Test
@ -68,7 +68,7 @@ public:
{
printName(result);
bool r = true; // TODO some tests
bool r = true; // TODO some tests
testAssert("Threads",r,result);

View file

@ -105,7 +105,7 @@ public:
SameType<TypeTraits<int>::ParameterType,int>::value &&
SameType<TypeTraits<double>::ParameterType,double>::value &&
SameType<TypeTraits<Test&>::ParameterType,Test &>::value &&
SameType<TypeTraits<Test>::ParameterType,const Test &>::value;
SameType<TypeTraits<Test>::ParameterType,const Test &>::value;
testAssert("TypeTraits",r,result);

View file

@ -180,7 +180,7 @@ private:
void testFunction();
void testFunctionPointer();
void testMemberFunctionPointer();
void testMemberFunctionPointer();
void testParameterType();
void testReferredType();
@ -220,7 +220,7 @@ inline void TypeTraitsTest2::execute(TestResult &result)
testFunction();
testFunctionPointer();
testMemberFunctionPointer();
testMemberFunctionPointer();
bool r = erroneousConditions_ == 0;
@ -581,7 +581,7 @@ inline void TypeTraitsTest2::testFunction()
#undef CONDITION
#define CONDITION isFunction
testBegin("isFunction");
testBegin("isFunction");
PASS(void());
PASS(void(int, float, ...));
@ -597,9 +597,9 @@ inline void TypeTraitsTest2::testFunctionPointer()
#undef CONDITION
#define CONDITION isFunctionPointer
testBegin("isFunctionPointer");
testBegin("isFunctionPointer");
PASS(void (*)());
PASS(void (*)());
FAIL(void (A::* const volatile)());
FAIL(void (A::* const volatile)() const);
FAIL(void (A::* const volatile)() volatile);
@ -624,7 +624,7 @@ inline void TypeTraitsTest2::testMemberFunctionPointer()
#undef CONDITION
#define CONDITION isMemberFunctionPointer
testBegin("isMemberFunctionPointer");
testBegin("isMemberFunctionPointer");
PASS(void (A::* const volatile)());
PASS(void (A::* const volatile)() const);

View file

@ -35,7 +35,7 @@ public:
using namespace Loki::TL;
#ifndef LOKI_DISABLE_TYPELIST_MACROS
typedef LOKI_TYPELIST_1(char) CharList;
typedef LOKI_TYPELIST_1(char) CharList;
typedef LOKI_TYPELIST_3(char,int,double) CharIntDoubleList;
typedef LOKI_TYPELIST_4(char,int,double,char) CharIntDoubleCharList;
typedef LOKI_TYPELIST_3(Base,Derived1,Derived2) BaseDerived1Derived2List;
@ -43,8 +43,8 @@ public:
typedef LOKI_TYPELIST_4(Base,Derived1,Base,Derived2) BaseDerived1BaseDerived2List;
typedef LOKI_TYPELIST_4(Derived1,Base,Derived1,Derived2) Derived1BaseDerived1Derived2List;
#else
typedef Seq<char>::Type CharList;
typedef Seq<char,int,double>::Type CharIntDoubleList;
typedef Seq<char>::Type CharList;
typedef Seq<char,int,double>::Type CharIntDoubleList;
typedef Seq<char,int,double,char>::Type CharIntDoubleCharList;
typedef Seq<Base,Derived1,Derived2>::Type BaseDerived1Derived2List;
typedef Seq<Derived2,Derived1,Base>::Type Derived2Derived1BaseList;
@ -179,8 +179,8 @@ public:
#else //LOKI_DISABLE_TYPELIST_MACROS
r=SameType<Append<NullType,NullType>::Result,NullType>::value &&
SameType<Append<NullType,char>::Result,Seq<char>::Type >::value &&
r=SameType<Append<NullType,NullType>::Result,NullType>::value &&
SameType<Append<NullType,char>::Result,Seq<char>::Type >::value &&
SameType<Append<NullType,CharList>::Result,CharList>::value &&
SameType<Append<CharList,NullType>::Result,CharList>::value &&
SameType<Append<CharList,int>::Result,Seq<char,int>::Type >::value &&
@ -254,7 +254,7 @@ public:
SameType<DerivedToFront<CharIntDoubleCharList>::Result,CharIntDoubleCharList>::value &&
SameType<DerivedToFront<BaseDerived1Derived2List>::Result,Derived2Derived1BaseList>::value &&
SameType<DerivedToFront<Derived2Derived1BaseList>::Result,Derived2Derived1BaseList>::value &&
SameType<DerivedToFront<BaseDerived1BaseDerived2List>::Result,Seq<Derived2,Derived1,Base,Base>::Type >::value &&
SameType<DerivedToFront<BaseDerived1BaseDerived2List>::Result,Seq<Derived2,Derived1,Base,Base>::Type >::value &&
SameType<DerivedToFront<Derived1BaseDerived1Derived2List>::Result,Seq<Derived2,Derived1,Derived1,Base>::Type >::value;
testAssert("DerivedToFront",r,result);

View file

@ -58,7 +58,7 @@ void TestCase(const string& fmt, T value) {
#ifdef _MSC_VER
const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value);
#else
const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value);
const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value);
#endif
if (i1 != i2 || s != buf) {

View file

@ -27,7 +27,7 @@
//#define COMPARE_BOOST_POOL
#ifdef COMPARE_BOOST_POOL
#include <boost\pool\object_pool.hpp>
#include <boost\pool\object_pool.hpp>
#endif
using namespace std;
@ -36,14 +36,14 @@ using namespace std;
template<unsigned int N>
class ThisIsASmallObject
{
char data[N];
char data[N];
};
template<unsigned int N, class T>
template<unsigned int N, class T>
struct Base : public ThisIsASmallObject<N>, public T
{};
template<unsigned int N>
template<unsigned int N>
struct Base<N, void> : public ThisIsASmallObject<N>
{};
@ -54,51 +54,51 @@ template<unsigned int N>
class BoostPoolNew : public Base<N,void>
{
private:
static boost::object_pool< BoostPoolNew<N> > BoostPool;
static boost::object_pool< BoostPoolNew<N> > BoostPool;
public:
/// Throwing single-object new throws bad_alloc when allocation fails.
/// 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 )
/// @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 )
static void * operator new ( std::size_t ) throw ( std::bad_alloc )
#endif
{
return BoostPool.malloc();
}
{
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();
}
/// 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 );
}
/// 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 ) );
}
/// 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 ) );
}
/** 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 );
}
/// Placement single-object delete merely calls global placement delete.
inline static void operator delete ( void * p, void * place )
{
::operator delete ( p, place );
}
};
@ -112,205 +112,208 @@ int array_test_nr = 0;
double t100_new = 0;
double t100_delete = 0;
#define LOKI_SMALLOBJ_BENCH(FUNC, CODE_LOOP) \
template<class T, int TN> \
int FUNC(void**, const int N, int loop, Timer& t, const char* s) \
{ \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_LOOP \
} \
/****************************************************************/ \
t.stop(); \
if(array_test_nr==0) \
t.t100 = t.t(); \
array_test_nr++; \
t.print(t.t(),s); \
return t.t(); \
#define LOKI_SMALLOBJ_BENCH(FUNC, CODE_LOOP) \
template<class T, int TN> \
int FUNC(void**, const int N, int loop, Timer& t, const char* s) \
{ \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_LOOP \
} \
/****************************************************************/ \
t.stop(); \
if(array_test_nr==0) \
t.t100 = t.t(); \
array_test_nr++; \
t.print(t.t(),s); \
return t.t(); \
}
#define LOKI_SMALLOBJ_BENCH_ARRAY(FUNC, CODE_DECL, CODE_NEW, CODE_DELETE) \
template<class T, int TN> \
int FUNC(void** arrv, const int N, int loop, Timer& t, const char* s) \
{ \
\
CODE_DECL; \
T** arr = reinterpret_cast<T**>(arrv); \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_NEW \
} \
/****************************************************************/ \
t.stop(); \
cout << "1. "; \
if(array_test_nr==0) \
{ \
t.t100 = t.t(); \
t100_new = t.t100; \
} \
else \
t.t100 = t100_new; \
t.print(t.t(),s); \
\
if(array_test_nr==3) \
{ \
cout << \
"2. boost :\tboost::object_pool is not tested because it's too slow"\
<< endl << endl; \
array_test_nr++; \
return t.t(); \
} \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_DELETE \
} \
/****************************************************************/ \
t.stop(); \
cout << "2. "; \
if(array_test_nr==0) \
{ \
t.t100 = t.t(); \
t100_delete = t.t100; \
} \
else \
t.t100 = t100_delete; \
t.print(t.t(),s); \
array_test_nr++; \
cout << endl; \
return t.t(); \
#define LOKI_SMALLOBJ_BENCH_ARRAY(FUNC, CODE_DECL, CODE_NEW, CODE_DELETE) \
template<class T, int TN> \
int FUNC(void** arrv, const int N, int loop, Timer& t, const char* s) \
{ \
\
CODE_DECL; \
T** arr = reinterpret_cast<T**>(arrv); \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_NEW \
} \
/****************************************************************/ \
t.stop(); \
cout << "1. "; \
if(array_test_nr==0) \
{ \
t.t100 = t.t(); \
t100_new = t.t100; \
} \
else \
t.t100 = t100_new; \
t.print(t.t(),s); \
\
if(array_test_nr==3) \
{ \
cout << \
"2. boost :\tboost::object_pool is not tested because it's too slow"\
<< endl << endl; \
array_test_nr++; \
return t.t(); \
} \
t.start(); \
/****************************************************************/ \
for (int i=0; i<loop; ++i) \
{ \
CODE_DELETE \
} \
/****************************************************************/ \
t.stop(); \
cout << "2. "; \
if(array_test_nr==0) \
{ \
t.t100 = t.t(); \
t100_delete = t.t100; \
} \
else \
t.t100 = t100_delete; \
t.print(t.t(),s); \
array_test_nr++; \
cout << endl; \
return t.t(); \
}
LOKI_SMALLOBJ_BENCH(delete_new ,delete new T;)
LOKI_SMALLOBJ_BENCH(delete_new_mal ,std::free(std::malloc(sizeof(T))););
LOKI_SMALLOBJ_BENCH(delete_new_all ,std::allocator<T> st;st.deallocate(st.allocate(1), 1);)
LOKI_SMALLOBJ_BENCH(delete_new ,delete new T;)
LOKI_SMALLOBJ_BENCH(delete_new_mal ,std::free(std::malloc(sizeof(T))););
LOKI_SMALLOBJ_BENCH(delete_new_all ,std::allocator<T> st;st.deallocate(st.allocate(1), 1);)
LOKI_SMALLOBJ_BENCH(delete_new_array ,delete[] new T[N];)
LOKI_SMALLOBJ_BENCH(delete_new_array ,delete[] new T[N];)
LOKI_SMALLOBJ_BENCH(delete_new_array_mal,std::free(std::malloc(sizeof(T[TN]))););
LOKI_SMALLOBJ_BENCH(delete_new_array_all,std::allocator<T[TN]> st;st.deallocate(st.allocate(1), 1);)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_on_arr , , arr[i] = new T; ,
delete arr[i];)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_on_arr , , arr[i] = new T; ,
delete arr[i];)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_on_arr_mal, , arr[i] = static_cast<T*>(std::malloc(sizeof(T))); ,
std::free(arr[i]);)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_on_arr_all, std::allocator<T> st ,
arr[i]=st.allocate(1); ,
st.deallocate(arr[i], 1);)
std::free(arr[i]);)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_on_arr_all, std::allocator<T> st ,
arr[i]=st.allocate(1); ,
st.deallocate(arr[i], 1);)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_a_on_a , , arr[i] = new T[TN]; ,
delete[] arr[i];)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_a_on_a , , arr[i] = new T[TN]; ,
delete[] arr[i];)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_a_on_a_mal, , arr[i] = static_cast<T*>(std::malloc(sizeof(T[TN]))); ,
std::free(arr[i]);)
std::free(arr[i]);)
LOKI_SMALLOBJ_BENCH_ARRAY(new_del_a_on_a_all,std::allocator<T[TN]> st ,
arr[i]=reinterpret_cast<T*>(st.allocate(1)); ,
st.deallocate(reinterpret_cast<T(*)[TN]>(arr[i]), 1);)
arr[i]=reinterpret_cast<T*>(st.allocate(1)); ,
st.deallocate(reinterpret_cast<T(*)[TN]>(arr[i]), 1);)
#ifndef COMPARE_BOOST_POOL
#define LOKI_SMALLOBJBECH_ABCD(FUNC,N,LOOP,TIMER,MESSAGE) \
array_test_nr = 0; \
cout << MESSAGE << endl; \
FUNC<A,N>(a,N,LOOP,TIMER,"new :"); \
FUNC<B,N>(a,N,LOOP,TIMER,"SmallObj :"); \
FUNC<C,N>(a,N,LOOP,TIMER,"ValueObj :"); \
FUNC##_all<A,N>(a,N,LOOP,TIMER,"allocator:"); \
FUNC##_mal<A,N>(a,N,LOOP,TIMER,"malloc :"); \
cout << endl << endl;
#define LOKI_SMALLOBJBECH_ABCD(FUNC,N,LOOP,TIMER,MESSAGE) \
array_test_nr = 0; \
cout << MESSAGE << endl; \
FUNC<A,N>(a,N,LOOP,TIMER,"new :"); \
FUNC<B,N>(a,N,LOOP,TIMER,"SmallObj :"); \
FUNC<C,N>(a,N,LOOP,TIMER,"ValueObj :"); \
FUNC##_all<A,N>(a,N,LOOP,TIMER,"allocator:"); \
FUNC##_mal<A,N>(a,N,LOOP,TIMER,"malloc :"); \
cout << endl << endl;
#else
#define LOKI_SMALLOBJBECH_ABCD(FUNC,N,LOOP,TIMER,MESSAGE) \
array_test_nr = 0; \
cout << MESSAGE << endl; \
FUNC<A,N>(a,N,LOOP,TIMER,"new :"); \
FUNC<B,N>(a,N,LOOP,TIMER,"SmallObj :"); \
FUNC<C,N>(a,N,LOOP,TIMER,"ValueObj :"); \
FUNC<D,N>(a,N,LOOP,TIMER,"boost :"); \
FUNC##_all<A,N>(a,N,LOOP,TIMER,"allocator:"); \
FUNC##_mal<A,N>(a,N,LOOP,TIMER,"malloc :"); \
cout << endl << endl;
#define LOKI_SMALLOBJBECH_ABCD(FUNC,N,LOOP,TIMER,MESSAGE) \
array_test_nr = 0; \
cout << MESSAGE << endl; \
FUNC<A,N>(a,N,LOOP,TIMER,"new :"); \
FUNC<B,N>(a,N,LOOP,TIMER,"SmallObj :"); \
FUNC<C,N>(a,N,LOOP,TIMER,"ValueObj :"); \
FUNC<D,N>(a,N,LOOP,TIMER,"boost :"); \
FUNC##_all<A,N>(a,N,LOOP,TIMER,"allocator:"); \
FUNC##_mal<A,N>(a,N,LOOP,TIMER,"malloc :"); \
cout << endl << endl;
#endif
template<unsigned int Size, int loop>
void testSize()
{
typedef Base<Size, void> A;
typedef Base<Size, Loki::SmallObject< Loki::SingleThreaded > > B;
typedef Base<Size, Loki::SmallValueObject< Loki::SingleThreaded > > C;
typedef Base<Size, void> A;
typedef Base<Size, Loki::SmallObject< Loki::SingleThreaded > > B;
typedef Base<Size, Loki::SmallValueObject< Loki::SingleThreaded > > C;
#ifdef COMPARE_BOOST_POOL
typedef BoostPoolNew<Size> D;
typedef BoostPoolNew<Size> D;
#endif
cout << endl << endl;
cout << "Allocator Benchmark Tests with " << Size << " bytes big objects " << endl;
cout << endl;
cout << "new = global new/delete \tsizeof(A) = " << sizeof(A) << endl;
cout << "SmallObj = Loki::SmallObject \tsizeof(B) = " << sizeof(B) << endl;
cout << "ValueObj = Loki::SmallValueObject\tsizeof(C) = " << sizeof(C) << endl;
cout << endl << endl;
cout << "Allocator Benchmark Tests with " << Size << " bytes big objects " << endl;
cout << endl;
cout << "new = global new/delete \tsizeof(A) = " << sizeof(A) << endl;
cout << "SmallObj = Loki::SmallObject \tsizeof(B) = " << sizeof(B) << endl;
cout << "ValueObj = Loki::SmallValueObject\tsizeof(C) = " << sizeof(C) << endl;
#ifdef COMPARE_BOOST_POOL
cout << "boost = boost::object_pool \tsizeof(D) = " << sizeof(D) << endl;
cout << "boost = boost::object_pool \tsizeof(D) = " << sizeof(D) << endl;
#endif
cout << "allocator= std::allocator \tsizeof(A) = " << sizeof(A) << endl;
cout << "malloc = std::malloc/free \tsizeof(A) = " << sizeof(A) << endl;
cout << endl << endl;
cout << "allocator= std::allocator \tsizeof(A) = " << sizeof(A) << endl;
cout << "malloc = std::malloc/free \tsizeof(A) = " << sizeof(A) << endl;
cout << endl << endl;
Timer t;
Timer t;
const int N = 3;
int Narr = 1000*1000;
const int N = 3;
int Narr = 1000*1000;
void** a= new void*[Narr];
void** a= new void*[Narr];
cout << loop << " times ";
LOKI_SMALLOBJBECH_ABCD(delete_new ,0,loop,t,"'delete new T'");
cout << "N=" << N <<" : " << loop << " times ";
LOKI_SMALLOBJBECH_ABCD(delete_new_array ,N,loop,t,"'delete[] new T[N]'");
cout << loop << " times ";
LOKI_SMALLOBJBECH_ABCD(delete_new ,0,loop,t,"'delete new T'");
cout << "N=" << N <<" : " << loop << " times ";
LOKI_SMALLOBJBECH_ABCD(delete_new_array ,N,loop,t,"'delete[] new T[N]'");
cout << "i=0..." << Narr << " : ";
LOKI_SMALLOBJBECH_ABCD(new_del_on_arr ,0,Narr,t,"1. 'arr[i] = new T' 2. 'delete arr[i]'");
cout << "i=0..." << Narr << ", N=" << N <<" : ";
LOKI_SMALLOBJBECH_ABCD(new_del_a_on_a ,N,Narr,t,"1. 'arr[i] = new T[N]' 2. 'delete[] arr[i]'");
cout << "i=0..." << Narr << " : ";
LOKI_SMALLOBJBECH_ABCD(new_del_on_arr ,0,Narr,t,"1. 'arr[i] = new T' 2. 'delete arr[i]'");
cout << "i=0..." << Narr << ", N=" << N <<" : ";
LOKI_SMALLOBJBECH_ABCD(new_del_a_on_a ,N,Narr,t,"1. 'arr[i] = new T[N]' 2. 'delete[] arr[i]'");
delete [] a;
cout << "_________________________________________________________________" << endl;
Loki::AllocatorSingleton<>::ClearExtraMemory();
delete [] a;
cout << "_________________________________________________________________" << endl;
Loki::AllocatorSingleton<>::ClearExtraMemory();
}
int main()
{
const int loop = 1000*1000;
const int loop = 1000*1000;
cout << endl;
cout << endl;
testSize< 2,loop>();
testSize< 3,loop>();
testSize< 8,loop>();
testSize< 9,loop>();
testSize<16,loop>();
testSize<17,loop>();
testSize< 2,loop>();
testSize< 3,loop>();
testSize< 8,loop>();
testSize< 9,loop>();
testSize<16,loop>();
testSize<17,loop>();
#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER)
// Stop console window from closing if run from IDE.
system("pause");
// Stop console window from closing if run from IDE.
system("pause");
#endif
return 0;
return 0;
}
// ----------------------------------------------------------------------------
// $Log$
// Revision 1.13 2005/10/30 14:03:23 syntheticpp
// replace tabs space
//
// Revision 1.12 2005/10/29 12:38:22 syntheticpp
// replace with new implementation
//

View file

@ -165,13 +165,16 @@ int main()
MortalSingleton::Instance().DoThat();
LongLivedSingleton::Instance().DoThat();
ImmortalSingleton::Instance().DoThat();
system("PAUSE");
return 0;
system("PAUSE");
return 0;
}
// ----------------------------------------------------------------------------
// $Log$
// Revision 1.3 2005/10/30 14:03:23 syntheticpp
// replace tabs space
//
// Revision 1.2 2005/10/29 10:21:46 syntheticpp
// find loki include files without a correct sreach pathand some small fixes
//

View file

@ -25,56 +25,59 @@ class Timer
{
public:
Timer()
{
t100 = 0;
};
Timer()
{
t100 = 0;
};
void start()
{
t0 = clock();
}
{
t0 = clock();
}
void stop()
{
t1 = clock();
}
int t()
{
return t1-t0;
}
{
t1 = clock();
}
int t()
{
return t1-t0;
}
double sec(int t)
{
return floor(100.0*double(t)/1000.0 )/100.0;
}
int rel(int t)
{
return ( t100==0 ? 100 : (int) floor(100.0*t/t100+0.5) );
}
double speedup(int t)
{
double tup=t;
return (tup!=0 ? floor(100.0*(t100!=0?t100:tup)/tup+0.5)/100 : 1);
}
double sec(int t)
{
return floor(100.0*double(t)/1000.0 )/100.0;
}
int rel(int t)
{
return ( t100==0 ? 100 : (int) floor(100.0*t/t100+0.5) );
}
double speedup(int t)
{
double tup=t;
return (tup!=0 ? floor(100.0*(t100!=0?t100:tup)/tup+0.5)/100 : 1);
}
double t100;
double t100;
void print(int t, const char* s)
{
void print(int t, const char* s)
{
std::cout << s << "\tseconds: " << sec(t) << "\trelative time: " << rel(t) << "%\tspeed-up factor: " << speedup(t) << "" << std::endl;
}
}
private:
int t0;
int t1;
int t1;
};
#endif
// $Log$
// Revision 1.5 2005/10/30 14:03:23 syntheticpp
// replace tabs space
//
// Revision 1.4 2005/10/26 00:38:49 rich_sposato
// Added CVS keywords and header lines.
//