/*************************************************************************** test_ublas.cpp : Test uBLAS ------------------- begin : Sun 2005-03-14 copyright : (C) 2005 by Paul C. Leopardi email : leopardi@bigpond.net.au *************************************************************************** * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of the * * License, or (at your option) any later version. * * See http://www.fsf.org/copyleft/lesser.html for details * ***************************************************************************/ #include "test_ublas.h" using namespace std; using namespace boost::numeric::ublas; using namespace ublas_test; void test_trial(int n) { matrix_index_t N = n; double total_neg_time = 0; double total_ass_time = 0; double total_sprod_time = 0; int n_trials = 1024; sparse_matrix mt(N,N); compressed_matrix ms0(N,N), ms2(N,N);//Later filled with N non zeros for (matrix_index_t k = 0; k != N; k++) { ms0(k,k) = 1.0/(1.0 + int(k)); ms2(k,N-k-1) = 1.0 + int(k); mt(k,N-k-1) = 1.0 + int(k); } for (int trial_n = 0; trial_n != n_trials; trial_n++) { compressed_matrix ms1(N,N);//Later filled with N non zeros for (matrix_index_t k = 0; k != N; k++) { ms1(k,k) = 1.0/(1.0 + int(k)); } clock_t cpu_time = clock(); compressed_matrix ms3(-ms1); total_neg_time += elapsed(cpu_time); cpu_time = clock(); ms1 = mt ; total_ass_time += elapsed(cpu_time); } int n_sprod_trials = 32; clock_t cpu_time = clock(); for (int trial_n = 0; trial_n != n_sprod_trials; trial_n++) { mt = prod(ms0,ms2); } total_sprod_time += elapsed(cpu_time); cout << "n: " << N << ", neg time: " << total_neg_time/n_trials << ", ass time: " << total_ass_time/n_trials << ", sprod time: " << total_sprod_time/n_sprod_trials << endl; } int main(int argc, char ** argv) { for (argc--, argv++; argc != 0; argc--, argv++) { int max_index = 0; sscanf(*argv, "%d", &max_index); if (max_index > 0) for (int n = 1; n < max_index+1; n *= 2) { test_trial(n); } } return 0; }