C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
exprtk_memleak_test.cpp
Go to the documentation of this file.
1/*
2 **************************************************************
3 * C++ Mathematical Expression Toolkit Library *
4 * *
5 * ExprTk Memory Leak Test *
6 * Author: Arash Partow (1999-2016) *
7 * URL: http://www.partow.net/programming/exprtk/index.html *
8 * *
9 * Copyright notice: *
10 * Free use of the Mathematical Expression Toolkit Library is *
11 * permitted under the guidelines and in accordance with the *
12 * most current version of the Common Public License. *
13 * http://www.opensource.org/licenses/cpl1.0.php *
14 * *
15 **************************************************************
16*/
17
18
19#include <cstdio>
20#include <fstream>
21#include <iostream>
22#include <string>
23#include <deque>
24
25#include "exprtk.hpp"
26
27template <typename Allocator,
28 template <typename,typename> class Sequence>
29inline std::size_t load_expressions(const std::string& file_name,
30 Sequence<std::string,Allocator>& sequence)
31{
32 std::ifstream stream(file_name.c_str());
33 if (!stream) return 0;
34 std::string buffer;
35 buffer.reserve(1024);
36 std::size_t line_count = 0;
37 while (std::getline(stream,buffer))
38 {
39 ++line_count;
40 sequence.push_back(buffer);
41 }
42 return line_count;
43}
44
45int main()
46{
47 std::deque<std::string> expr_str_list;
48
49 load_expressions("pgo_expression_list.txt",expr_str_list);
50
51 typedef std::deque<exprtk::expression<double> > exprlist_t;
53
54 static const std::size_t rounds = 100;
55
56 exprtk::timer timer;
57 timer.start();
58 for (std::size_t r = 0; r < rounds; ++r)
59 {
60 exprlist_t expression_list;
61 symbol_table.add_constants();
62 symbol_table.create_variable("x",2.2);
63 symbol_table.create_variable("y",3.3);
64 symbol_table.create_variable("z",4.4);
65 symbol_table.create_variable("w",5.5);
66
69
70 temp_expr.register_symbol_table(symbol_table);
71
72 for (std::size_t i = 0; i < expr_str_list.size(); ++i)
73 {
74 if (!parser.compile(expr_str_list[i],temp_expr))
75 {
76 printf("[load_expression] - [%04d] Parser Error: %s\tExpression: %s\n",
77 i,
78 parser.error().c_str(),
79 expr_str_list[i].c_str());
80 }
81 else
82 expression_list.push_back(temp_expr);
83 }
84
85 for (std::size_t i = 0; i < expression_list.size(); ++i)
86 {
87 expression_list[i].value();
88 }
89
90 if (0 == (r % 10))
91 {
92 std::cout << "Round: " << r << std::endl;
93 }
94 }
95 timer.stop();
96
97 printf("Total Time:%12.8fsec Rate:%15.5fcompiles/sec\n",
98 timer.time(),
99 (rounds * expr_str_list.size()) / timer.time());
100
101
102
103 return 0;
104}
void register_symbol_table(symbol_table< T > &st)
Definition exprtk.hpp:20992
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:23584
std::string error() const
Definition exprtk.hpp:23858
bool create_variable(const std::string &variable_name, const T &value=T(0))
Definition exprtk.hpp:20054
double time() const
Definition exprtk.hpp:41912
static const std::size_t rounds
std::size_t load_expressions(const std::string &file_name, Sequence< std::string, Allocator > &sequence)
int main()
static const std::string expression_list[]