3 #include <ginac/ginac.h>
9 * Demonstrates the use of compile_ex.
11 * Compiles a small expression as C code via compile_ex and evaluates the
12 * expression numerically. The evalation speed is timed and compared to the
13 * evaluation of the original GiNaC expression.
19 // Define some expression
23 // Some variables for timing
27 // Our function pointer that points to the compiled ex
30 // Optionally, compile with custom compiler flags:
31 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
32 compile_ex(expr, x, fp);
34 // Do some (not necessarily meaningful ;-)) numerical stuff ...
36 cout << "Doing numerics with compile_ex ..." << endl;
38 // First using compile_ex
43 for (int i=0; i<100000; ++i) {
50 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
51 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
54 cout << "Doing numerics without compile_ex ..." << endl;
56 // Then without compile_ex
61 for (int i=0; i<100000; ++i) {
67 // Show the other result
68 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
69 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;