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
28 compile_ex(expr, x, fp);
30 // Do some (not necessarily meaningful ;-)) numerical stuff ...
32 cout << "Doing numerics with compile_ex ..." << endl;
34 // First using compile_ex
39 for (int i=0; i<100000; ++i) {
46 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
47 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;
50 cout << "Doing numerics without compile_ex ..." << endl;
52 // Then without compile_ex
57 for (int i=0; i<100000; ++i) {
63 // Show the other result
64 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
65 cout << "result = " << result << " in " << cpu_time_used << " seconds" << endl;