Skip to content

Commit c0c0a9b

Browse files
committed
Added TinyExpr
1 parent c945a92 commit c0c0a9b

22 files changed

+2005
-2
lines changed

include/BenchTinyExpr.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef BENCH_TINYEXPR_H
2+
#define BENCH_TINYEXPR_H
3+
4+
#include <vector>
5+
#include <string>
6+
7+
#include "Benchmark.h"
8+
9+
//-------------------------------------------------------------------------------------------------
10+
class BenchTinyExpr : public Benchmark
11+
{
12+
public:
13+
14+
BenchTinyExpr();
15+
16+
double DoBenchmark(const std::string& sExpr, long iCount);
17+
};
18+
19+
#endif

math-parser-benchmark-project/math-parser-benchmark-project.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<ClInclude Include="..\include\BenchMuParserSSE.h" />
173173
<ClInclude Include="..\include\BenchMuParserX.h" />
174174
<ClInclude Include="..\include\BenchNative.h" />
175+
<ClInclude Include="..\include\BenchTinyExpr.h" />
175176
<ClInclude Include="..\include\cpuid.h" />
176177
<ClInclude Include="..\include\FormelGenerator.h" />
177178
<ClInclude Include="..\include\Stopwatch.h" />
@@ -281,6 +282,7 @@
281282
<ClInclude Include="..\muparserx\suSortPred.h" />
282283
<ClInclude Include="..\muparserx\suStringTokens.h" />
283284
<ClInclude Include="..\muparserx\utGeneric.h" />
285+
<ClInclude Include="..\tinyexpr\tinyexpr.h" />
284286
</ItemGroup>
285287
<ItemGroup>
286288
<ClCompile Include="..\AsmJit\AssemblerX86X64.cpp" />
@@ -383,10 +385,12 @@
383385
<ClCompile Include="..\src\BenchMuParserSSE.cpp" />
384386
<ClCompile Include="..\src\BenchMuParserX.cpp" />
385387
<ClCompile Include="..\src\BenchNative.cpp" />
388+
<ClCompile Include="..\src\BenchTinyExpr.cpp" />
386389
<ClCompile Include="..\src\cpuid.cpp" />
387390
<ClCompile Include="..\src\FormelGenerator.cpp" />
388391
<ClCompile Include="..\src\ParserBench.cpp" />
389392
<ClCompile Include="..\src\Stopwatch.cpp" />
393+
<ClCompile Include="..\tinyexpr\tinyexpr.c" />
390394
</ItemGroup>
391395
<ItemGroup>
392396
<None Include="..\chaiscript\language\chaiscript_prelude.chai" />

math-parser-benchmark-project/math-parser-benchmark-project.vcxproj.filters

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@
277277
<ClCompile Include="..\AsmJit\VirtualMemory.cpp">
278278
<Filter>asmjit</Filter>
279279
</ClCompile>
280+
<ClCompile Include="..\tinyexpr\tinyexpr.c">
281+
<Filter>tinyexpr</Filter>
282+
</ClCompile>
283+
<ClCompile Include="..\src\BenchTinyExpr.cpp" />
280284
</ItemGroup>
281285
<ItemGroup>
282286
<ClInclude Include="..\atmsp\atmsp.base.h">
@@ -819,6 +823,12 @@
819823
<ClInclude Include="..\AsmJit\WarningsPush.h">
820824
<Filter>asmjit</Filter>
821825
</ClInclude>
826+
<ClInclude Include="..\tinyexpr\tinyexpr.h">
827+
<Filter>tinyexpr</Filter>
828+
</ClInclude>
829+
<ClInclude Include="..\include\BenchTinyExpr.h">
830+
<Filter>headers</Filter>
831+
</ClInclude>
822832
</ItemGroup>
823833
<ItemGroup>
824834
<None Include="..\fparser\fparser.hh">
@@ -871,5 +881,8 @@
871881
<Filter Include="asmjit">
872882
<UniqueIdentifier>{64c71230-dd29-4c16-99e9-34d50edaf410}</UniqueIdentifier>
873883
</Filter>
884+
<Filter Include="tinyexpr">
885+
<UniqueIdentifier>{b1b43109-aa45-419d-bf8d-437e1b5cbab8}</UniqueIdentifier>
886+
</Filter>
874887
</ItemGroup>
875888
</Project>

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ following expression parsers are part of this benchmark:
1212
| 03 | [Lepton] (https://simtk.org/home/lepton) | Peter Eastman | [MIT](http://www.opensource.org/licenses/mit-license.php) | double |
1313
| 04 | [MathExpr] (http://www.yann-ollivier.org/mathlib/mathexpr)| Yann Ollivier | [Copyright Notice 1997-2000](http://www.yann-ollivier.org/mathlib/mathexpr#C)| double |
1414
| 05 | [MTParser] (http://www.codeproject.com/Articles/7335/An-extensible-math-expression-parser-with-plug-ins)| Mathieu Jacques | [CPOL](http://www.codeproject.com/info/cpol10.aspx)| double |
15-
| 06 | [muParser] (http://muparser.beltoforion.de/) | Ingo Berg | [MIT](http://www.opensource.org/licenses/mit-license.php) | double, float |
16-
| 07 | [muParserX](http://muparserx.beltoforion.de/) | Ingo Berg | [MIT](http://www.opensource.org/licenses/mit-license.php) | double, float |
15+
| 06 | [muParser] (http://muparser.beltoforion.de) | Ingo Berg | [MIT](http://www.opensource.org/licenses/mit-license.php) | double, float |
16+
| 07 | [muParserX](http://muparserx.beltoforion.de) | Ingo Berg | [MIT](http://www.opensource.org/licenses/mit-license.php) | double, float |
17+
| 08 | [TinyExpr] (https://github.com/codeplea/tinyexpr) | Lewis Van Winkle | [zlib](https://opensource.org/licenses/Zlib) | double |
1718

1819

1920
**Note:** This archive is not meant as a primary source for any of the

src/BenchTinyExpr.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include "BenchTinyExpr.h"
2+
3+
#include <cmath>
4+
5+
#include "tinyexpr/tinyexpr.h"
6+
7+
8+
//-------------------------------------------------------------------------------------------------
9+
BenchTinyExpr::BenchTinyExpr()
10+
: Benchmark()
11+
{
12+
m_sName = "TinyExpr";
13+
}
14+
15+
//-------------------------------------------------------------------------------------------------
16+
double BenchTinyExpr::DoBenchmark(const std::string& sExpr, long iCount)
17+
{
18+
double a = 1.1;
19+
double b = 2.2;
20+
double c = 3.3;
21+
double x = 2.123456;
22+
double y = 3.123456;
23+
double z = 4.123456;
24+
double w = 5.123456;
25+
double e = 2.718281828459045235360;
26+
double p = 3.141592653589793238462;
27+
28+
te_variable vars[] =
29+
{
30+
{"a", &a},
31+
{"b", &b},
32+
{"c", &c},
33+
{"x", &x},
34+
{"y", &y},
35+
{"z", &z},
36+
{"w", &w},
37+
{"e", &e},
38+
{"pi",&p}
39+
};
40+
41+
int error = 0;
42+
te_expr* expression = reinterpret_cast<te_expr*>(0);
43+
44+
expression = te_compile(sExpr.c_str(), vars, sizeof(vars) / sizeof(te_variable), &error);
45+
46+
if ((0 == expression) || error)
47+
{
48+
StopTimer(std::numeric_limits<double>::quiet_NaN(),
49+
std::numeric_limits<double>::quiet_NaN(),
50+
1);
51+
52+
return std::numeric_limits<double>::quiet_NaN();
53+
}
54+
55+
//Prime the I and D caches for the expression
56+
{
57+
double d0 = 0.0;
58+
double d1 = 0.0;
59+
60+
for (std::size_t i = 0; i < priming_rounds; ++i)
61+
{
62+
if (i & 1)
63+
d0 += te_eval(expression);
64+
else
65+
d1 += te_eval(expression);
66+
}
67+
68+
if (
69+
(d0 == std::numeric_limits<double>::infinity()) &&
70+
(d1 == std::numeric_limits<double>::infinity())
71+
)
72+
{
73+
printf("\n");
74+
}
75+
}
76+
77+
// Perform benchmark then return results
78+
double fRes = 0;
79+
double fSum = 0;
80+
81+
fRes = te_eval(expression);
82+
83+
StartTimer();
84+
85+
for (int j = 0; j < iCount; ++j)
86+
{
87+
fSum += te_eval(expression);
88+
std::swap(a,b);
89+
std::swap(x,y);
90+
}
91+
92+
StopTimer(fRes, fSum, iCount);
93+
94+
te_free(expression);
95+
96+
return m_fTime1;
97+
}

src/ParserBench.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "BenchLepton.h"
3232
#include "BenchFParser.h"
3333
#include "BenchMathExpr.h"
34+
#include "BenchTinyExpr.h"
3435
#include "BenchNative.h"
3536

3637
#ifdef ENABLE_MPFR
@@ -485,6 +486,7 @@ int main(int argc, const char *argv[])
485486
vBenchmarks.push_back(new BenchLepton() );
486487
vBenchmarks.push_back(new BenchFParser() );
487488
vBenchmarks.push_back(new BenchMathExpr() );
489+
vBenchmarks.push_back(new BenchTinyExpr() );
488490
#if defined(_MSC_VER) && defined(NDEBUG)
489491
vBenchmarks.push_back(new BenchMTParser() ); // <-- Crash in debug mode
490492
#endif

tinyexpr/.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: c
2+
3+
compiler:
4+
- clang
5+
- gcc
6+
7+
script: make

tinyexpr/LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
TINYEXPR - Tiny recursive descent parser and evaluation engine in C
2+
3+
Copyright (c) 2015, 2016 Lewis Van Winkle
4+
5+
http://CodePlea.com
6+
7+
This software is provided 'as-is', without any express or implied
8+
warranty. In no event will the authors be held liable for any damages
9+
arising from the use of this software.
10+
11+
Permission is granted to anyone to use this software for any purpose,
12+
including commercial applications, and to alter it and redistribute it
13+
freely, subject to the following restrictions:
14+
15+
1. The origin of this software must not be misrepresented; you must not
16+
claim that you wrote the original software. If you use this software
17+
in a product, an acknowledgement in the product documentation would be
18+
appreciated but is not required.
19+
2. Altered source versions must be plainly marked as such, and must not be
20+
misrepresented as being the original software.
21+
3. This notice may not be removed or altered from any source distribution.
22+

tinyexpr/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CCFLAGS = -ansi -Wall -Wshadow -O2
2+
LFLAGS = -lm
3+
4+
5+
all: test bench example example2 example3
6+
7+
8+
test: test.o tinyexpr.o
9+
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
10+
./$@
11+
12+
13+
bench: benchmark.o tinyexpr.o
14+
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
15+
16+
example: example.o tinyexpr.o
17+
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
18+
19+
example2: example2.o tinyexpr.o
20+
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
21+
22+
example3: example3.o tinyexpr.o
23+
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
24+
25+
.c.o:
26+
$(CC) -c $(CCFLAGS) $< -o $@
27+
28+
29+
clean:
30+
rm *.o
31+
rm *.exe

0 commit comments

Comments
 (0)