[complement-svn] SF.net SVN: complement:[1958] trunk/complement/explore/perf/alloc
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-08-13 09:29:19
|
Revision: 1958 http://complement.svn.sourceforge.net/complement/?rev=1958&view=rev Author: complement Date: 2008-08-13 09:29:15 +0000 (Wed, 13 Aug 2008) Log Message: ----------- less expencive tests: free some memory Modified Paths: -------------- trunk/complement/explore/perf/alloc/alloc_perf_suite.cc trunk/complement/explore/perf/alloc/alloc_perf_suite.h trunk/complement/explore/perf/alloc/suite.cc Modified: trunk/complement/explore/perf/alloc/alloc_perf_suite.cc =================================================================== --- trunk/complement/explore/perf/alloc/alloc_perf_suite.cc 2008-08-12 14:32:04 UTC (rev 1957) +++ trunk/complement/explore/perf/alloc/alloc_perf_suite.cc 2008-08-13 09:29:15 UTC (rev 1958) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/08/12 18:28:14 yeti> +// -*- C++ -*- Time-stamp: <08/08/13 13:28:22 yeti> /* * Copyright (c) 2008 @@ -8,13 +8,23 @@ */ #include "alloc_perf_suite.h" +#include <vector> +#include <mt/thread> +#include <mt/mutex> + using namespace std; +vector<void *> p( 1000 ); + int EXAM_IMPL(alloc_test::alloc) { for ( int i = 0; i < 10000; ++i ) { - if ( malloc( 100 ) == 0 ) { + if ( p[i % 1000] != 0 ) { + free( p[i % 1000] ); + } + p[i % 1000] = malloc( 100 ); + if ( p[i % 1000] == 0 ) { return 1; } } @@ -25,7 +35,11 @@ int EXAM_IMPL(alloc_test::alloc5000) { for ( int i = 0; i < 10000; ++i ) { - if ( malloc( 5000 ) == 0 ) { + if ( p[i % 1000] != 0 ) { + free( p[i % 1000] ); + } + p[i % 1000] = malloc( 5000 ); + if ( p[i % 1000] == 0 ) { return 1; } } @@ -36,7 +50,11 @@ int EXAM_IMPL(alloc_test::alloc_mix) { for ( int i = 0; i < 5000; ++i ) { - if ( malloc( 5000 ) == 0 ) { + if ( p[i % 1000] != 0 ) { + free( p[i % 1000] ); + } + p[i % 1000] = malloc( 5000 ); + if ( p[i % 1000] == 0 ) { return 1; } if ( malloc( 100 ) == 0 ) { @@ -46,3 +64,34 @@ return 0; } + +static std::tr2::mutex lk; + +void a0() +{ + for ( int i = 0; i < 10000; ++i ) { + std::tr2::lock_guard<std::tr2::mutex> lock( lk ); + + if ( p[i % 1000] != 0 ) { + free( p[i % 1000] ); + } + p[i % 1000] = malloc( 100 ); + } +} + +int EXAM_IMPL(alloc_test::alloc_t5) +{ + std::tr2::basic_thread<0,0> t0( a0 ); + std::tr2::basic_thread<0,0> t1( a0 ); + std::tr2::basic_thread<0,0> t2( a0 ); + std::tr2::basic_thread<0,0> t3( a0 ); + std::tr2::basic_thread<0,0> t4( a0 ); + + t0.join(); + t1.join(); + t2.join(); + t3.join(); + t4.join(); + + return 0; +} Modified: trunk/complement/explore/perf/alloc/alloc_perf_suite.h =================================================================== --- trunk/complement/explore/perf/alloc/alloc_perf_suite.h 2008-08-12 14:32:04 UTC (rev 1957) +++ trunk/complement/explore/perf/alloc/alloc_perf_suite.h 2008-08-13 09:29:15 UTC (rev 1958) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/08/12 18:28:37 yeti> +// -*- C++ -*- Time-stamp: <08/08/13 13:26:19 yeti> /* * Copyright (c) 2008 @@ -18,6 +18,7 @@ int EXAM_DECL(alloc); int EXAM_DECL(alloc5000); int EXAM_DECL(alloc_mix); + int EXAM_DECL(alloc_t5); }; #endif // __ALLOC_PERF_SUITE_H Modified: trunk/complement/explore/perf/alloc/suite.cc =================================================================== --- trunk/complement/explore/perf/alloc/suite.cc 2008-08-12 14:32:04 UTC (rev 1957) +++ trunk/complement/explore/perf/alloc/suite.cc 2008-08-13 09:29:15 UTC (rev 1958) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/08/12 18:27:28 yeti> +// -*- C++ -*- Time-stamp: <08/08/13 13:26:45 yeti> /* * Copyright (c) 2008 @@ -27,6 +27,7 @@ t.add( &alloc_test::alloc, alt, "malloc" ); t.add( &alloc_test::alloc5000, alt, "malloc 5000" ); t.add( &alloc_test::alloc_mix, alt, "malloc mix" ); + t.add( &alloc_test::alloc_t5, alt, "malloc 5 threads" ); return t.girdle(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |