@@ -42,11 +42,12 @@ Expression examples:
4242
4343 // external data in expression (aka variables)
4444 foobar := 123
45- varFunc := func(name []byte) ( *xpression.Operand, error) {
45+ varFunc := func(name []byte, result *xpression.Operator) error {
4646 mapper := map[string]*int{
4747 `foobar`: &foobar
4848 }
49- return xpression.Number(float64(*mapper[string(name)])), nil
49+ xpression.SetNumber(float64(*mapper[string(name)]))
50+ return nil
5051 }
5152 tokens, err := xpression.Parse([]byte(`27 / foobar`))
5253 result, err := xpression.Evaluate(tokens, varFunc)
@@ -81,35 +82,36 @@ Tests cover the majority of cases described in ECMAScript Language definition (s
8182
8283Evaluate ` (2) + (2) == (4) `
8384
84- ``` diff
85+ ``` golang
8586$ go test -bench=. -benchmem -benchtime=4s
8687goos: darwin
8788goarch: amd64
8889pkg: github.com /bhmj/xpression
8990cpu: Intel (R) Core (TM) i9-9880H CPU @ 2. 30GHz
90- Benchmark_ModifiedNumericLiteral_WithParsing-16 2714204 1853 ns/op 1272 B/op 26 allocs/op
91- Benchmark_ModifiedNumericLiteral_WithoutParsing-16 31129712 143.9 ns/op 128 B/op 2 allocs/op
91+ Benchmark_ModifiedNumericLiteral_WithParsing-16 2622770 1811 ns/op 1272 B /op 26 allocs/op
92+ Benchmark_ModifiedNumericLiteral_WithoutParsing-16 77455698 57.55 ns/op 0 B /op 0 allocs/op
9293PASS
93- ok github.com/bhmj/xpression 12.363s
94+ ok github.com /bhmj/xpression 11. 548s
9495```
9596
9697The same expression evaluated with [ github.com/Knetic/govaluate] ( https://github.com/Knetic/govaluate ) :
9798
98- ``` diff
99+ ``` golang
99100$ go test -bench=' LiteralModifiers' -benchmem -benchtime=4s
100101goos: darwin
101102goarch: amd64
102103pkg: github.com /Knetic/govaluate
103104cpu: Intel (R) Core (TM) i9-9880H CPU @ 2. 30GHz
104- BenchmarkEvaluationLiteralModifiers_WithParsing-16 1000000 4019 ns/op 2208 B/op 43 allocs/op
105- BenchmarkEvaluationLiteralModifiers-16 30173640 147.2 ns/op 8 B/op 1 allocs/op
105+ BenchmarkEvaluationLiteralModifiers_WithParsing-16 1000000 4019 ns/op 2208 B /op 43 allocs/op
106+ BenchmarkEvaluationLiteralModifiers-16 30173640 147.2 ns/op 8 B /op 1 allocs/op
106107PASS
107108ok github.com /Knetic/govaluate 9. 810s
108109```
109110
110111
111112## Changelog
112113
114+ ** 0.9.0** (2021-11-19) -- Memory allocation reduced. Speed optimization.
113115** 0.8.0** (2021-11-11) -- hex numbers support. Production ready.
114116** 0.7.x** (2021-11-11) -- WIP
115117** 0.7.0** (2021-11-10) -- project renamed to ` xpression `
@@ -131,7 +133,7 @@ ok github.com/Knetic/govaluate 9.810s
131133- [x] parser test coverage
132134- [x] evaluator test coverage
133135- [x] add external reference type (node reference in jsonslice)
134- - [ ] optimize memory allocations
136+ - [x ] optimize memory allocations
135137- [ ] Unicode support!
136138
137139## Contributing
0 commit comments