[eigen] Proposal to remove aligned alloc paths |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Attachment:
no-mm-malloc
Description: Binary data
Attachment:
malloc-not-already-aligned
Description: Binary data
#include <bench/BenchTimer.h> #include <iostream> #include <vector> using namespace std; using namespace Eigen; const size_t iters = 1000000; void test(size_t maxsize, size_t alignment) { if (alignment) { cout << "posix_memalign+free with " << alignment << "-byte alignment "; } else { cout << "malloc+free "; } cout << "for random sizes between 0 and " << maxsize << "..." << endl; vector<size_t> sizes; for (size_t i = 0; i < iters; ++i) { // only test sizes that are multiples of 4 bytes to be realistic wrt Eigen sizes.push_back((rand() % maxsize) & ~3); } BenchTimer timer; double startrealtime = timer.getRealTime(), startcputime = timer.getCpuTime(); for (size_t i = 0; i < iters; ++i) { void *p; if (alignment) { posix_memalign(&p, alignment, sizes[i]); } else { p = malloc(sizes[i]); } free(p); } double endrealtime = timer.getRealTime(), endcputime = timer.getCpuTime(); cout << "Real:" << (endrealtime - startrealtime) / iters << " s, CPU: " << (endcputime - startcputime) / iters << " s" << endl; } int main() { cout.precision(3); test(10, 0); test(10, 16); test(10, 32); test(1000, 0); test(1000, 16); test(1000, 32); test(100000, 0); test(100000, 16); test(100000, 32); test(10000000, 0); test(10000000, 16); test(10000000, 32); }
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |