[Assorted-commits] SF.net SVN: assorted: [394] numa-bench/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-12 19:17:49
|
Revision: 394 http://assorted.svn.sourceforge.net/assorted/?rev=394&view=rev Author: yangzhang Date: 2008-02-12 11:16:18 -0800 (Tue, 12 Feb 2008) Log Message: ----------- added custom_alloc test Modified Paths: -------------- numa-bench/trunk/src/Makefile Added Paths: ----------- numa-bench/trunk/src/custom_alloc.cc Modified: numa-bench/trunk/src/Makefile =================================================================== --- numa-bench/trunk/src/Makefile 2008-02-12 18:01:24 UTC (rev 393) +++ numa-bench/trunk/src/Makefile 2008-02-12 19:16:18 UTC (rev 394) @@ -16,6 +16,9 @@ threads: threads.cc $(COMMONS) $(CXX) +custom_alloc: custom_alloc.cc + $(CXX) + openmp: openmp.cc $(CXX) -fopenmp Added: numa-bench/trunk/src/custom_alloc.cc =================================================================== --- numa-bench/trunk/src/custom_alloc.cc (rev 0) +++ numa-bench/trunk/src/custom_alloc.cc 2008-02-12 19:16:18 UTC (rev 394) @@ -0,0 +1,60 @@ +// TODO: add in test of tbb allocator. + +#include <commons/region.h> +#include <commons/time.h> +#include <commons/boost/threads.h> +#include <boost/bind.hpp> + +using namespace boost; +using namespace commons; + +void +f(region_alloc<int>* a, int count) +{ + timer t("region: "); + int* j = NULL; + for (int i = 0; i < count; i++) { + j = a->allocate(1); + } + t.print(); + cout << j << endl; +} + +void +g(int count) +{ + timer t("new: "); + int* j = NULL; + for (int i = 0; i < count; i++) { + j = new int; + } + t.print(); + cout << j << endl; +} + +int +main() +{ + int ncores = 16; + int count = 1000000; + pthread_t ts[ncores]; + + // This is much faster. + { + region_alloc<int> as[ncores]; + for (int i = 0; i < ncores; i++) { + check((ts[i] = spawn(bind(f, &as[i], count))) != 0); + } + waitall(ts, ncores); + } + + // This is much slower. + { + for (int i = 0; i < ncores; i++) { + check((ts[i] = spawn(bind(g, count))) != 0); + } + waitall(ts, ncores); + } + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |