6 #include <ginac/ginac.h>
12 * Demonstrates the use of compile_ex.
14 * Compiles a small expression as C code via compile_ex and evaluates the
15 * expression numerically. The evalation speed is timed and compared to the
16 * evaluation of the original GiNaC expression.
22 // Define some expression
26 // Some variables for timing
30 // Our function pointer that points to the compiled ex
33 // Optionally, compile with custom compiler flags:
34 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
35 compile_ex(expr, x, fp);
37 // Do some (not necessarily meaningful ;-)) numerical stuff ...
39 cout << "Doing numerics with compile_ex ..." << endl;
41 // First using compile_ex
46 for (int i=0; i<100000; ++i) {
53 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
54 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
57 cout << "Doing numerics without compile_ex ..." << endl;
59 // Then without compile_ex
64 for (int i=0; i<100000; ++i) {
70 // Show the other result
71 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
72 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;