This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
PATCH (libstdc++-v3): Improve allocator performance tests
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 30 Jan 2004 02:31:23 -0600 (CST)
- Subject: PATCH (libstdc++-v3): Improve allocator performance tests
- Reply-to: rittle at labs dot mot dot com
As committed to mainline (based on earlier observations made on
libstdc++ list that default allocator had an in-test advantage and
that adding the ports $THREAD_FLAG may affect allocator performance,
which should be revealed by these tests).
BTW, some results of this change are counterintuitive; which makes me
very glad I did it... E.g. __mt_alloc test in allocator.cc without
-pthread performs much better than with -pthread as expected; the
other allocators appear to perform slightly better with -pthread!
Loren
* scripts/check_performance: Only compile with $THREAD_FLAG
when test is marked to require it. Allow multiple
compilations/executions of marked tests.
* testsuite/testsuite_performance.h (report_performance):
Report dynamic thread support status.
(report_header): Likewise.
* testsuite/performance/allocator.cc: Stabilize iteration
count. Support more allocators. Mark each allocator test to
run and report independently.
* testsuite/performance/allocator_map_thread.cc: Likewise.
* testsuite/performance/allocator_thread.cc: Likewise.
(All other performance tests should compile, run, and report
exactly as before except none will see $THREAD_FLAG.)
Index: libstdc++-v3/scripts/check_performance
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/scripts/check_performance,v
retrieving revision 1.2
diff -c -r1.2 check_performance
*** libstdc++-v3/scripts/check_performance 7 Jan 2004 05:59:16 -0000 1.2
--- libstdc++-v3/scripts/check_performance 30 Jan 2004 08:15:36 -0000
***************
*** 31,49 ****
-Wl,--rpath -Wl,$BUILD_DIR/src/.libs"
ST_FLAG="-static"
LINK=$SH_FLAG
! CXX="$COMPILER $INCLUDES $FLAGS $THREAD_FLAG $LINK"
TESTS_FILE="testsuite_files_performance"
for NAME in `cat $TESTS_FILE`
do
! echo $NAME
! FILE_NAME="`basename $NAME`"
! EXE_NAME="`echo $FILE_NAME | sed 's/cc$/exe/'`"
! $CXX $SRC_DIR/testsuite/$NAME -o $EXE_NAME
! ./$EXE_NAME
! echo ""
done
exit 0
--- 31,73 ----
-Wl,--rpath -Wl,$BUILD_DIR/src/.libs"
ST_FLAG="-static"
LINK=$SH_FLAG
! CXX="$COMPILER $INCLUDES $FLAGS $LINK"
! CXX_THREAD="$COMPILER $INCLUDES $FLAGS $THREAD_FLAG $LINK"
TESTS_FILE="testsuite_files_performance"
for NAME in `cat $TESTS_FILE`
do
! RUN=true
! for CYCLE in `sed -n 's,.*\(TEST_[SB][0-9]*\)$,\1,p' $SRC_DIR/testsuite/$NAME`
! do
! RUN=false
! echo $NAME $CYCLE
! FILE_NAME="`basename $NAME`"
! EXE_NAME="`echo $FILE_NAME-$CYCLE | sed 's/cc$/exe/'`"
! $CXX -D$CYCLE $SRC_DIR/testsuite/$NAME -o $EXE_NAME
! ./$EXE_NAME
! echo ""
! done
! for CYCLE in `sed -n 's,.*\(TEST_[TB][0-9]*\)$,\1,p' $SRC_DIR/testsuite/$NAME`
! do
! RUN=false
! echo $NAME $CYCLE THREAD
! FILE_NAME="`basename $NAME`"
! EXE_NAME="`echo $FILE_NAME-$CYCLE | sed 's/cc$/exe/'`"
! $CXX_THREAD -D$CYCLE $SRC_DIR/testsuite/$NAME -o $EXE_NAME
! ./$EXE_NAME
! echo ""
! done
! if $RUN; then
! echo $NAME
! FILE_NAME="`basename $NAME`"
! EXE_NAME="`echo $FILE_NAME | sed 's/cc$/exe/'`"
! $CXX $SRC_DIR/testsuite/$NAME -o $EXE_NAME
! ./$EXE_NAME
! echo ""
! fi
done
exit 0
Index: libstdc++-v3/testsuite/testsuite_performance.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/testsuite_performance.h,v
retrieving revision 1.11
diff -c -r1.11 testsuite_performance.h
*** libstdc++-v3/testsuite/testsuite_performance.h 17 Dec 2003 10:16:03 -0000 1.11
--- libstdc++-v3/testsuite/testsuite_performance.h 30 Jan 2004 08:15:37 -0000
***************
*** 183,188 ****
--- 183,193 ----
std::ofstream out(name, std::ios_base::app);
+ #ifdef __GTHREADS
+ if (__gthread_active_p ())
+ testname.append ("-thread");
+ #endif
+
out.setf(std::ios_base::left);
out << std::setw(25) << testname << tab;
out << std::setw(25) << comment << tab;
***************
*** 208,213 ****
--- 213,223 ----
std::string testname(i, file.end());
std::ofstream out(name, std::ios_base::app);
+
+ #ifdef __GTHREADS
+ if (__gthread_active_p ())
+ testname.append ("-thread");
+ #endif
out.setf(std::ios_base::left);
out << std::setw(25) << testname << tab;
Index: libstdc++-v3/testsuite/performance/allocator.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/performance/allocator.cc,v
retrieving revision 1.7
diff -c -r1.7 allocator.cc
*** libstdc++-v3/testsuite/performance/allocator.cc 14 Jan 2004 18:54:18 -0000 1.7
--- libstdc++-v3/testsuite/performance/allocator.cc 30 Jan 2004 08:15:47 -0000
***************
*** 38,55 ****
#include <typeinfo>
#include <sstream>
#include <ext/mt_allocator.h>
#include <ext/malloc_allocator.h>
#include <cxxabi.h>
#include <testsuite_performance.h>
using namespace std;
- using __gnu_cxx::malloc_allocator;
using __gnu_cxx::__mt_alloc;
typedef int test_type;
// The number of iterations to be performed.
! int iterations;
// The number of values to insert in the container, 32 will cause 5
// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
--- 38,57 ----
#include <typeinfo>
#include <sstream>
#include <ext/mt_allocator.h>
+ #include <ext/new_allocator.h>
#include <ext/malloc_allocator.h>
#include <cxxabi.h>
#include <testsuite_performance.h>
using namespace std;
using __gnu_cxx::__mt_alloc;
+ using __gnu_cxx::new_allocator;
+ using __gnu_cxx::malloc_allocator;
typedef int test_type;
// The number of iterations to be performed.
! int iterations = 100000;
// The number of values to insert in the container, 32 will cause 5
// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
***************
*** 83,111 ****
template<typename Container>
void
- calibrate_iterations()
- {
- int try_iterations = iterations = 100000;
- int test_iterations;
-
- __gnu_test::time_counter timer;
- timer.start();
- test_iterations = do_loop<Container>();
- timer.stop();
-
- if (try_iterations > test_iterations && test_iterations > iterations)
- iterations = test_iterations - 100;
- else
- {
- double tics = timer.real_time();
- double iterpc = test_iterations / tics; //iterations per clock
- double xtics = 200; // works for linux 2gig x86
- iterations = static_cast<int>(xtics * iterpc);
- }
- }
-
- template<typename Container>
- void
test_container(Container obj)
{
using namespace __gnu_test;
--- 85,90 ----
***************
*** 130,144 ****
// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
int main(void)
{
! calibrate_iterations<vector<test_type> >();
test_container(vector<test_type>());
test_container(vector<test_type, malloc_allocator<test_type> >());
test_container(vector<test_type, __mt_alloc<test_type> >());
! calibrate_iterations<list<test_type> >();
test_container(list<test_type>());
test_container(list<test_type, malloc_allocator<test_type> >());
test_container(list<test_type, __mt_alloc<test_type> >());
return 0;
}
--- 109,139 ----
// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
int main(void)
{
! #ifdef TEST_B1
test_container(vector<test_type>());
+ #endif
+ #ifdef TEST_B2
test_container(vector<test_type, malloc_allocator<test_type> >());
+ #endif
+ #ifdef TEST_B3
+ test_container(vector<test_type, new_allocator<test_type> >());
+ #endif
+ #ifdef TEST_B4
test_container(vector<test_type, __mt_alloc<test_type> >());
+ #endif
! #ifdef TEST_B5
test_container(list<test_type>());
+ #endif
+ #ifdef TEST_B6
test_container(list<test_type, malloc_allocator<test_type> >());
+ #endif
+ #ifdef TEST_B7
+ test_container(list<test_type, new_allocator<test_type> >());
+ #endif
+ #ifdef TEST_B8
test_container(list<test_type, __mt_alloc<test_type> >());
+ #endif
return 0;
}
Index: libstdc++-v3/testsuite/performance/allocator_map_thread.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/performance/allocator_map_thread.cc,v
retrieving revision 1.1
diff -c -r1.1 allocator_map_thread.cc
*** libstdc++-v3/testsuite/performance/allocator_map_thread.cc 23 Jan 2004 06:54:06 -0000 1.1
--- libstdc++-v3/testsuite/performance/allocator_map_thread.cc 30 Jan 2004 08:15:47 -0000
***************
*** 37,53 ****
#include <iostream>
#include <typeinfo>
#include <sstream>
- #include <cxxabi.h>
#include <ext/mt_allocator.h>
#include <ext/malloc_allocator.h>
#include <testsuite_performance.h>
using namespace std;
- using __gnu_cxx::malloc_allocator;
using __gnu_cxx::__mt_alloc;
// The number of iterations to be performed.
! int iterations;
template<typename Container>
void*
--- 37,55 ----
#include <iostream>
#include <typeinfo>
#include <sstream>
#include <ext/mt_allocator.h>
+ #include <ext/new_allocator.h>
#include <ext/malloc_allocator.h>
+ #include <cxxabi.h>
#include <testsuite_performance.h>
using namespace std;
using __gnu_cxx::__mt_alloc;
+ using __gnu_cxx::new_allocator;
+ using __gnu_cxx::malloc_allocator;
// The number of iterations to be performed.
! int iterations = 25000;
template<typename Container>
void*
***************
*** 71,93 ****
template<typename Container>
void
- calibrate_iterations()
- {
- int try_iterations = iterations = 10000;
-
- __gnu_test::time_counter timer;
- timer.start();
- do_loop<Container>();
- timer.stop();
-
- double tics = timer.real_time();
- double iterpc = iterations / tics; //iterations per clock
- double xtics = 100; // works for linux 2gig x86
- iterations = static_cast<int>(xtics * iterpc);
- }
-
- template<typename Container>
- void
test_container(Container obj)
{
using namespace __gnu_test;
--- 73,78 ----
***************
*** 122,132 ****
int main(void)
{
! calibrate_iterations<map<int, int> >();
test_container(map<int, int>());
test_container(map<int, int, less<const int>, malloc_allocator<int> >());
test_container(map<int, int, less<const int>,
__mt_alloc< pair<const int, int> > >());
return 0;
}
--- 107,125 ----
int main(void)
{
! #ifdef TEST_T1
test_container(map<int, int>());
+ #endif
+ #ifdef TEST_T2
+ test_container(map<int, int, less<const int>, new_allocator<int> >());
+ #endif
+ #ifdef TEST_T3
test_container(map<int, int, less<const int>, malloc_allocator<int> >());
+ #endif
+ #ifdef TEST_T4
test_container(map<int, int, less<const int>,
__mt_alloc< pair<const int, int> > >());
+ #endif
return 0;
}
Index: libstdc++-v3/testsuite/performance/allocator_thread.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/performance/allocator_thread.cc,v
retrieving revision 1.3
diff -c -r1.3 allocator_thread.cc
*** libstdc++-v3/testsuite/performance/allocator_thread.cc 14 Jan 2004 18:54:18 -0000 1.3
--- libstdc++-v3/testsuite/performance/allocator_thread.cc 30 Jan 2004 08:15:47 -0000
***************
*** 39,56 ****
#include <sstream>
#include <pthread.h>
#include <ext/mt_allocator.h>
#include <ext/malloc_allocator.h>
#include <cxxabi.h>
#include <testsuite_performance.h>
using namespace std;
- using __gnu_cxx::malloc_allocator;
using __gnu_cxx::__mt_alloc;
typedef int test_type;
// The number of iterations to be performed.
! int iterations;
// The number of values to insert in the container, 32 will cause 5
// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
--- 39,58 ----
#include <sstream>
#include <pthread.h>
#include <ext/mt_allocator.h>
+ #include <ext/new_allocator.h>
#include <ext/malloc_allocator.h>
#include <cxxabi.h>
#include <testsuite_performance.h>
using namespace std;
using __gnu_cxx::__mt_alloc;
+ using __gnu_cxx::new_allocator;
+ using __gnu_cxx::malloc_allocator;
typedef int test_type;
// The number of iterations to be performed.
! int iterations = 25000;
// The number of values to insert in the container, 32 will cause 5
// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
***************
*** 91,113 ****
template<typename Container>
void
- calibrate_iterations()
- {
- int try_iterations = iterations = 100000;
-
- __gnu_test::time_counter timer;
- timer.start();
- do_loop<Container>();
- timer.stop();
-
- double tics = timer.real_time();
- double iterpc = iterations / tics; //iterations per clock
- double xtics = 100; // works for linux 2gig x86
- iterations = static_cast<int>(xtics * iterpc);
- }
-
- template<typename Container>
- void
test_container(Container obj)
{
using namespace __gnu_test;
--- 93,98 ----
***************
*** 144,158 ****
// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
int main(void)
{
! calibrate_iterations<vector<test_type> >();
test_container(vector<test_type>());
test_container(vector<test_type, malloc_allocator<test_type> >());
test_container(vector<test_type, __mt_alloc<test_type> >());
! calibrate_iterations<list<test_type> >();
test_container(list<test_type>());
test_container(list<test_type, malloc_allocator<test_type> >());
test_container(list<test_type, __mt_alloc<test_type> >());
return 0;
}
--- 129,159 ----
// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
int main(void)
{
! #ifdef TEST_T1
test_container(vector<test_type>());
+ #endif
+ #ifdef TEST_T2
test_container(vector<test_type, malloc_allocator<test_type> >());
+ #endif
+ #ifdef TEST_T3
+ test_container(vector<test_type, new_allocator<test_type> >());
+ #endif
+ #ifdef TEST_T4
test_container(vector<test_type, __mt_alloc<test_type> >());
+ #endif
! #ifdef TEST_T5
test_container(list<test_type>());
+ #endif
+ #ifdef TEST_T6
test_container(list<test_type, malloc_allocator<test_type> >());
+ #endif
+ #ifdef TEST_T7
+ test_container(list<test_type, new_allocator<test_type> >());
+ #endif
+ #ifdef TEST_T8
test_container(list<test_type, __mt_alloc<test_type> >());
+ #endif
return 0;
}