C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Functions | Variables
exprtk_pgo.cpp File Reference
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
#include <deque>
#include "exprtk.hpp"
Include dependency graph for exprtk_pgo.cpp:

Go to the source code of this file.

Functions

template<typename Allocator , template< typename, typename > class Sequence>
std::size_t load_expressions (const std::string &file_name, Sequence< std::string, Allocator > &sequence)
 
int main ()
 

Variables

static const double lower_bound_x = -100.0
 
static const double lower_bound_y = -100.0
 
static const double upper_bound_x = +100.0
 
static const double upper_bound_y = +100.0
 
static const double delta = 0.0111
 

Function Documentation

◆ load_expressions()

template<typename Allocator , template< typename, typename > class Sequence>
std::size_t load_expressions ( const std::string &  file_name,
Sequence< std::string, Allocator > &  sequence 
)
inline

Definition at line 37 of file exprtk_pgo.cpp.

39{
40 std::ifstream stream(file_name.c_str());
41 if (!stream) return 0;
42 std::string buffer;
43 buffer.reserve(1024);
44 std::size_t line_count = 0;
45 while (std::getline(stream,buffer))
46 {
47 ++line_count;
48 sequence.push_back(buffer);
49 }
50 return line_count;
51}

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( )

Definition at line 53 of file exprtk_pgo.cpp.

54{
55 std::deque<std::string> expr_str_list;
56
57 double x = 0.0;
58 double y = 0.0;
59 double z = 0.0;
60 double w = 0.0;
61
63 symbol_table.add_constants();
64 symbol_table.add_variable("x",x);
65 symbol_table.add_variable("y",y);
66 symbol_table.add_variable("z",z);
67 symbol_table.add_variable("w",w);
68
69 std::deque<exprtk::expression<double> > expression_list;
70
73
74 temp_expr.register_symbol_table(symbol_table);
75
76 {
77 static const std::size_t rounds = 10;
78 for (std::size_t r = 0; r < rounds; r++)
79 {
80 load_expressions("pgo_expression_list.txt",expr_str_list);
81
82 for (std::size_t i = 0; i < expr_str_list.size(); ++i)
83 {
84 if (!parser.compile(expr_str_list[i],temp_expr))
85 {
86 printf("[load_expression] - [%04d] Parser Error: %s\tExpression: %s\n",
87 i,
88 parser.error().c_str(),
89 expr_str_list[i].c_str());
90 }
91 else
92 expression_list.push_back(temp_expr);
93 }
94
95 std::cout << "Expression load: " << r << " Loaded: " << expression_list.size() << std::endl;
96 expr_str_list.clear();
97 expression_list.clear();
98 }
99 }
100
101 {
102 load_expressions("pgo_expression_list.txt",expr_str_list);
103
104 for (std::size_t i = 0; i < expr_str_list.size(); ++i)
105 {
106 if (!parser.compile(expr_str_list[i],temp_expr))
107 {
108 printf("[load_expression] - [%04d] Parser Error: %s\tExpression: %s\n",
109 i,
110 parser.error().c_str(),
111 expr_str_list[i].c_str());
112 }
113 else
114 expression_list.push_back(temp_expr);
115 }
116
117 static const std::size_t rounds = 100000;
118 double total = 0.0;
119
120 exprtk::timer timer;
121 timer.start();
122
123 x = 0.001;
124 y = 0.002;
125 z = 0.003;
126 w = 0.004;
127
128 for (std::size_t r = 0; r < rounds; r++)
129 {
130 for (std::size_t i = 0; i < expression_list.size(); ++i)
131 {
132 total += expression_list[i].value();
133 }
134
135 x += 0.01;
136 y += 0.02;
137 z += 0.03;
138 w += 0.04;
139 }
140
141 timer.stop();
142
143 if (0.0 != total)
144 {
145 printf("Total Time:%12.8fsec Rate:%15.5fevals/sec\n",
146 timer.time(),
147 (rounds * expression_list.size()) / timer.time());
148 }
149 }
150
151 return 0;
152}
bool register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:21726
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24443
std::string error() const
Definition exprtk.hpp:24722
bool add_variable(const std::string &variable_name, T &t, const bool is_constant=false)
Definition exprtk.hpp:20770
double time() const
Definition exprtk.hpp:43502
static const std::size_t rounds
std::size_t load_expressions(const std::string &file_name, Sequence< std::string, Allocator > &sequence)
static const std::string expression_list[]

References exprtk::symbol_table< T >::add_constants(), exprtk::symbol_table< T >::add_variable(), exprtk::parser< T >::compile(), exprtk::parser< T >::error(), expression_list, load_expressions(), exprtk::expression< T >::register_symbol_table(), rounds, exprtk::timer::start(), exprtk::timer::stop(), and exprtk::timer::time().

Here is the call graph for this function:

Variable Documentation

◆ delta

const double delta = 0.0111
static

Definition at line 32 of file exprtk_pgo.cpp.

Referenced by pgo_primer(), polynomial(), run_test07(), square_wave(), and square_wave2().

◆ lower_bound_x

const double lower_bound_x = -100.0
static

Definition at line 28 of file exprtk_pgo.cpp.

Referenced by pgo_primer().

◆ lower_bound_y

const double lower_bound_y = -100.0
static

Definition at line 29 of file exprtk_pgo.cpp.

Referenced by pgo_primer().

◆ upper_bound_x

const double upper_bound_x = +100.0
static

Definition at line 30 of file exprtk_pgo.cpp.

Referenced by pgo_primer().

◆ upper_bound_y

const double upper_bound_y = +100.0
static

Definition at line 31 of file exprtk_pgo.cpp.

Referenced by pgo_primer().