The following code will illustrate this behavior:
#include "matlab.hpp"#include <stdlib.h> /* used for EXIT_SUCCESS */#ifdef GCC#ifndef EXIT_SUCCESS#define EXIT_SUCCESS 0#endif#endifint main(void){#ifdef EXCEPTIONS_WORK try#endif { mwArray a, b, c, x, y, z; // x = rand(4,4); //y = magic(7); //z = eig(x);for( int i=1; i<30000;i++){x(i)=i;y(i)=i;z(i)=i;//if (i%10000==0) cout<<i<<endl;
} // Save (and name) the variables save("ex5.mat", "x", x, "y", y, "z", z); // Load the named variables load("ex5.mat", "x", &a, "y", &b, "z", &c); // Check to be sure the variables are equal if (tobool(a == x) && tobool(b == y) && tobool(c == z)) { cout << "Success: all variables equal" << endl; } else { cout << "Failure: loaded values not equal to saved values" << endl; } }#ifdef EXCEPTIONS_WORK catch (mwException &ex) { cout << ex; }#endif return(EXIT_SUCCESS);}
Testing this example for different values of i yielded the following results. For 300 elements the execution time was .32 seconds; for 3,000 elements it was 2.173 seconds; and for 30,000 elements it was 388 seconds. The execution time seems to be growing exponentially.
Best Answer