- cout << "start integration of " << expr << " ..." << endl;
-
- // Some definitions for VEGAS
- #define NDIM 2
- #define NCOMP 1
- #define EPSREL 1e-3
- #define EPSABS 1e-12
- #define VERBOSE 0
- #define MINEVAL 0
- #define MAXEVAL 50000
- #define NSTART 1000
- #define NINCREASE 500
-
- // Some variables for VEGAS
- int comp, nregions, neval, fail;
- double integral[NCOMP], error[NCOMP], prob[NCOMP];
-
- // Starting VEGAS
- // By invocation of compile() the expression in expr is converted into the
- // appropriate function pointer
- Vegas(NDIM, NCOMP, compile(lst(expr), lst(x,y)), EPSREL, EPSABS, VERBOSE,
- MINEVAL, MAXEVAL, NSTART, NINCREASE, &neval, &fail, integral, error, prob);
-
- // Show the result
- cout << "result: " << integral[0] << endl;
+ // Some variables for timing
+ time_t start, end;
+ double cpu_time_used;
+
+ // Our function pointer that points to the compiled ex
+ FUNCP_1P fp;
+ compile_ex(expr, x, fp);
+
+ // Do some (not necessarily meaningful ;-)) numerical stuff ...
+
+ cout << "Doing numerics with compile_ex ..." << endl;
+
+ // First using compile_ex
+ {
+ double result;
+ double point = 0.2;
+ start = clock();
+ for (int i=0; i<100000; ++i) {
+ point += 0.001;
+ result += fp(point);
+ }
+ end = clock();
+
+ // Show the result
+ cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+ cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
+ }
+
+ cout << "Doing numerics without compile_ex ..." << endl;
+
+ // Then without compile_ex
+ {
+ ex result;
+ ex point = 0.2;
+ start = clock();
+ for (int i=0; i<100000; ++i) {
+ point += 0.001;
+ result += sin(point);
+ }
+ end = clock();
+
+ // Show the other result
+ cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+ cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
+ }