Skip to content

Commit 52f341d

Browse files
committed
Updated Exprtk
1 parent 307022f commit 52f341d

File tree

2 files changed

+139
-10
lines changed

2 files changed

+139
-10
lines changed

exprtk/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ OPTIMIZATION_OPT = -O1
2121
BASE_OPTIONS = -pedantic-errors -Wall -Wextra -Werror -Wno-long-long
2222
OPTIONS = $(BASE_OPTIONS) $(OPTIMIZATION_OPT)
2323
LINKER_OPT = -L/usr/lib -lstdc++ -lm
24+
ASAN_OPT = -g -fsanitize=address -fno-omit-frame-pointer
25+
MSAN_OPT = -g -fsanitize=memory -fno-omit-frame-pointer
26+
LSAN_OPT = -g -fsanitize=leak -fno-omit-frame-pointer
2427

2528
BUILD_LIST+=exprtk_test
2629
BUILD_LIST+=exprtk_benchmark

exprtk/readme.txt

Lines changed: 136 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ C++ Mathematical Expression Toolkit Library Documentation
2424
Section 21 - Compilation Errors
2525
Section 22 - Runtime Library Packages
2626
Section 23 - Helpers & Utils
27-
Section 24 - Exprtk Notes
28-
Section 25 - Simple Exprtk Example
29-
Section 26 - Build Options
30-
Section 27 - Files
31-
Section 28 - Language Structure
27+
Section 24 - Benchmarking
28+
Section 25 - Exprtk Notes
29+
Section 26 - Simple Exprtk Example
30+
Section 27 - Build Options
31+
Section 28 - Files
32+
Section 29 - Language Structure
3233

3334

3435
[00 - INTRODUCTION]
@@ -3438,7 +3439,132 @@ a name in string form. Example usage of the function is as follows:
34383439

34393440
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34403441

3441-
[24 - EXPRTK NOTES]
3442+
[24 - BENCHMARKING]
3443+
As part of the ExprTk package there is an expression benchmark utility
3444+
named 'exprtk_benchmark'. The utility attempts to determine expression
3445+
evaluation speed (or rate of evaluations - evals per second), by
3446+
evaluating each expression numerous times and mutating the underlying
3447+
variables of the expression between each evaluation. The utility
3448+
assumes any valid ExprTk expression (containing conditionals, loops
3449+
etc), however it will only make use of a predefined set of scalar
3450+
variables, namely: a, b, c, x, y, z, w. That being said expressions
3451+
themselves can contain any number of local variables, vectors or
3452+
strings. There are two modes of operation:
3453+
3454+
(1) Default
3455+
(2) User Specified Expressions
3456+
3457+
3458+
(1) Default
3459+
The default mode is enabled simply by executing the exprtk_benchmark
3460+
binary with no command line parameters. In this mode a predefined set
3461+
of expressions will be evaluated in three phases:
3462+
3463+
(a) ExprTk evaluation
3464+
(b) Native evaluation
3465+
(c) ExprTk parse
3466+
3467+
3468+
In the first two phases (a and b) a list of predefined (hard-coded)
3469+
expressions will be evaluated using both ExprTk and native mode
3470+
implementations. This is done so as to compare evaluation times
3471+
between ExprTk and native implementations. The set of expressions used
3472+
are as follows:
3473+
3474+
(01) (y + x)
3475+
(02) 2 * (y + x)
3476+
(03) (2 * y + 2 * x)
3477+
(04) ((1.23 * x^2) / y) - 123.123
3478+
(05) (y + x / y) * (x - y / x)
3479+
(06) x / ((x + y) + (x - y)) / y
3480+
(07) 1 - ((x * y) + (y / x)) - 3
3481+
(08) (5.5 + x) + (2 * x - 2 / 3 * y) * (x / 3 + y / 4) + (y + 7.7)
3482+
(09) 1.1x^1 + 2.2y^2 - 3.3x^3 + 4.4y^15 - 5.5x^23 + 6.6y^55
3483+
(10) sin(2 * x) + cos(pi / y)
3484+
(11) 1 - sin(2 * x) + cos(pi / y)
3485+
(12) sqrt(111.111 - sin(2 * x) + cos(pi / y) / 333.333)
3486+
(13) (x^2 / sin(2 * pi / y)) - x / 2
3487+
(14) x + (cos(y - sin(2 / x * pi)) - sin(x - cos(2 * y / pi))) - y
3488+
(15) clamp(-1.0, sin(2 * pi * x) + cos(y / 2 * pi), +1.0)
3489+
(16) max(3.33, min(sqrt(1 - sin(2 * x) + cos(pi / y) / 3), 1.11))
3490+
(17) if((y + (x * 2.2)) <= (x + y + 1.1), x - y, x*y) + 2 * pi / x
3491+
3492+
3493+
The third and final phase (c), is used to determine average
3494+
compilation rates (compiles per second) for expressions of varying
3495+
complexity. Each expression is compiled 100K times and the average for
3496+
each expression is output.
3497+
3498+
3499+
(2) User Specified Expressions
3500+
In this mode two parameters are passed to the utility via the command
3501+
line:
3502+
3503+
(a) A name of a text file containing one expression per line
3504+
(b) An integer representing the number of evaluations per expression
3505+
3506+
3507+
An example execution of the benchmark utility in this mode is as
3508+
follows:
3509+
3510+
./exprtk_benchmark my_expressions.txt 1000000
3511+
3512+
3513+
The above invocation will load the expressions from the file
3514+
'my_expressions.txt' and will then proceed to evaluate each expression
3515+
one million times, varying the above mentioned variables (x, y, z
3516+
etc.) between each evaluation, and at the end of each expression round
3517+
a print out of running times, result of a single evaluation and total
3518+
sum of results is provided as demonstrated below:
3519+
3520+
Expression 1 of 7 4.770 ns 47700 ns ( 9370368.0) '((((x+y)+z)))'
3521+
Expression 2 of 7 4.750 ns 47500 ns ( 1123455.9) '((((x+y)-z)))'
3522+
Expression 3 of 7 4.766 ns 47659 ns (21635410.7) '((((x+y)*z)))'
3523+
Expression 4 of 7 5.662 ns 56619 ns ( 1272454.9) '((((x+y)/z)))'
3524+
Expression 5 of 7 4.950 ns 49500 ns ( 4123455.9) '((((x-y)+z)))'
3525+
Expression 6 of 7 7.581 ns 75810 ns (-4123455.9) '((((x-y)-z)))'
3526+
Expression 7 of 7 4.801 ns 48010 ns ( 0.0) '((((x-y)*z)))'
3527+
3528+
3529+
The benchmark utility can be very useful when investigating evaluation
3530+
efficiency issues with ExprTk or simply during the prototyping of
3531+
expressions. As an example, lets take the following expression:
3532+
3533+
1 / sqrt(2x) * e^(3y)
3534+
3535+
3536+
Let's say we would like to determine which sub-part of the expression
3537+
takes the most time to evaluate and perhaps attempt to rework the
3538+
expression based on the results. In order to do this we will create a
3539+
text file called 'test.txt' and then proceed to make some educated
3540+
guesses about how to break the expression up into its more
3541+
'interesting' sub-parts which we will then add as one expression per
3542+
line to the file. An example breakdown may be as follows:
3543+
3544+
1 / sqrt(2x) * e^(3y)
3545+
1 / sqrt(2x)
3546+
e^(3y)
3547+
3548+
3549+
The benchmark with the given file, where each expression will be
3550+
evaluated 100K times can be executed as follows:
3551+
3552+
./exprtk_benchmark test.txt 100000
3553+
Expr 1 of 3 90.340 ns 9034000 ns (296417859.3) '1/sqrt(2x)*e^(3y)'
3554+
Expr 2 of 3 11.100 ns 1109999 ns ( 44267.3) '1/sqrt(2x)'
3555+
Expr 3 of 3 77.830 ns 7783000 ns (615985286.6) 'e^(3y)'
3556+
[*] Number Of Evals: 300000
3557+
[*] Total Time: 0.018sec
3558+
[*] Total Single Eval Time: 0.000ms
3559+
3560+
3561+
From the results above we can see that the third expression (e^(3y))
3562+
consumes the largest amount of time and should perhaps be replaced
3563+
with the 'exp' function for more efficient evaluation.
3564+
3565+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3566+
3567+
[25 - EXPRTK NOTES]
34423568
The following is a list of facts and suggestions one may want to take
34433569
into account when using ExprTk:
34443570

@@ -3639,7 +3765,7 @@ into account when using ExprTk:
36393765

36403766
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36413767

3642-
[25 - SIMPLE EXPRTK EXAMPLE]
3768+
[26 - SIMPLE EXPRTK EXAMPLE]
36433769
The following is a simple yet complete example demonstrating typical
36443770
usage of the ExprTk Library. The example instantiates a symbol table
36453771
object, adding to it three variables named x, y and z, and a custom
@@ -3744,7 +3870,7 @@ int main()
37443870

37453871
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37463872

3747-
[26 - BUILD OPTIONS]
3873+
[27 - BUILD OPTIONS]
37483874
When building ExprTk there are a number of defines that will enable or
37493875
disable certain features and capabilities. The defines can either be
37503876
part of a compiler command line switch or scoped around the include to
@@ -3811,7 +3937,7 @@ error.
38113937

38123938
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38133939

3814-
[27 - FILES]
3940+
[28 - FILES]
38153941
The source distribution of ExprTk is comprised of the following set of
38163942
files:
38173943

@@ -3842,7 +3968,7 @@ files:
38423968

38433969
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38443970

3845-
[28 - LANGUAGE STRUCTURE]
3971+
[29 - LANGUAGE STRUCTURE]
38463972
+-------------------------------------------------------------+
38473973
|00 - If Statement |
38483974
| |

0 commit comments

Comments
 (0)