Function parser for C++: Speed tests
These tests were performed by running each specific test many times in
a loop and then averaging the total time with the number of loops performed.
The parsing, evaluation, evaluation after optimization, and optimization
speeds were measured. The time is specified in microseconds (µs).
(Note that the actual speeds may vary more than the amount of used
significant digits in the list below from execution to execution. The
most significant digit is nevertheless quite accurate.)
These tests were run with the version 4.0.2 of the FunctionParser library.
Test platform 1
The following results were obtained on a
3.4GHz Pentium4 using gcc 4.3.1
with the compiler options -O3 -ffast-math -march=native
Function:
"x^14 + y^8"
- Parse time: 0.98 µs. (1 016 906 parses/s)
- Eval time: 0.11 µs. (8 862 419 evals/s)
- Optimized: 0.11 µs. (8 980 207 evals/s)
- Optimization time: 55 µs. (17 944 optimizes/s)
Function:
"((3*x^4-7*x^3+2*x^2-4*x+10) - (4*y^3+2*y^2-10*y+2))*10"
- Parse time: 4.70 µs. (212 666 parses/s)
- Eval time: 0.48 µs. (2 099 682 evals/s)
- Optimized: 0.24 µs. (4 236 076 evals/s)
- Optimization time: 1486 µs. (672 optimizes/s)
Function:
"((3*(x+(5*(y+2)-7*x)*3-y)+4*5+3)-7+(8*x+5*y+(7-x))*4)-10*3+4"
- Parse time: 4.79 µs. (208 879 parses/s)
- Eval time: 0.39 µs. (2 560 678 evals/s)
- Optimized: 0.06 µs. (15 654 719 evals/s)
- Optimization time: 830 µs. (1 203 optimizes/s)
Function:
"(tan(x)*cos(x))^2 - 1.2*log(atan2(sqrt((-y^2)+1), y) * 4.91^y) + cos(-x)^2"
- Parse time: 3.74 µs. (267 641 parses/s)
- Eval time: 0.59 µs. (1 705 450 evals/s)
- Optimized: 0.23 µs. (4 284 095 evals/s)
- Optimization time: 403 µs. (2 480 optimizes/s)
Function:
"exp((-x*x-y*y)/100)*sin(sqrt(x*x+y*y))/(10*2) + sin(pow(x,4)-4*pow(x,3)+3*x*x-2*x+2*5-3) - cos(-2*pow(y,4)+5*pow(y,3)-14*x*x+8*x-120/2+4)"
- Parse time: 8.48 µs. (117 928 parses/s)
- Eval time: 1.05 µs. (948 600 evals/s)
- Optimized: 0.91 µs. (1 098 860 evals/s)
- Optimization time: 1537 µs. (650 optimizes/s)
Test platform 2
The following results were obtained on a
2.4GHz Intel Core2 Quad using gcc 4.3.4
Function:
"x^14 + y^8"
- Parse time: 0.54 µs. (1 839 063 parses/s)
- Eval time: 0.05 µs. (20 000 400 evals/s)
- Optimized: 0.06 µs. (17 295 203 evals/s)
- Optimization time: 30 µs. (32 638 optimizes/s)
Function:
"((3*x^4-7*x^3+2*x^2-4*x+10) - (4*y^3+2*y^2-10*y+2))*10"
- Parse time: 2.85 µs. (350 548 parses/s)
- Eval time: 0.15 µs. (6 478 341 evals/s)
- Optimized: 0.18 µs. (5 605 789 evals/s)
- Optimization time: 786 µs. (1 272 optimizes/s)
Function:
"((3*(x+(5*(y+2)-7*x)*3-y)+4*5+3)-7+(8*x+5*y+(7-x))*4)-10*3+4"
- Parse time: 3.04 µs. (329 059 parses/s)
- Eval time: 0.20 µs. (4 914 004 evals/s)
- Optimized: 0.04 µs. (27 088 525 evals/s)
- Optimization time: 442 µs. (2 260 optimizes/s)
Function:
"(tan(x)*cos(x))^2 - 1.2*log(atan2(sqrt((-y^2)+1), y) * 4.91^y) + cos(-x)^2"
- Parse time: 2.25 µs. (444 006 parses/s)
- Eval time: 0.43 µs. (2 320 314 evals/s)
- Optimized: 0.15 µs. (6 684 022 evals/s)
- Optimization time: 220 µs. (4 535 optimizes/s)
Function:
"exp((-x*x-y*y)/100)*sin(sqrt(x*x+y*y))/(10*2) + sin(pow(x,4)-4*pow(x,3)+3*x*x-2*x+2*5-3) - cos(-2*pow(y,4)+5*pow(y,3)-14*x*x+8*x-120/2+4)"
- Parse time: 5.22 µs. (191 479 parses/s)
- Eval time: 0.49 µs. (2 029 859 evals/s)
- Optimized: 0.45 µs. (2 246 166 evals/s)
- Optimization time: 817 µs. (1 223 optimizes/s)