4 #include <ginac/ginac.h>
8 * Demonstrates the use of compile_ex.
10 * Compiles a small expression as C code via compile_ex and evaluates the
11 * expression numerically. The evalation speed is timed and compared to the
12 * evaluation of the original GiNaC expression.
18 // Define some expression
22 // Some variables for timing
26 // Our function pointer that points to the compiled ex
29 // Optionally, compile with custom compiler flags:
30 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
31 compile_ex(expr, x, fp);
33 // Do some (not necessarily meaningful ;-)) numerical stuff ...
35 cout << "Doing numerics with compile_ex ..." << endl;
37 // First using compile_ex
42 for (int i=0; i<100000; ++i) {
49 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
50 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
53 cout << "Doing numerics without compile_ex ..." << endl;
55 // Then without compile_ex
60 for (int i=0; i<100000; ++i) {
66 // Show the other result
67 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
68 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;