mirror of
https://github.com/danog/liquid.git
synced 2024-11-26 22:24:39 +01:00
Benchmarks
This commit is contained in:
parent
51517990c9
commit
023fca4617
@ -1,7 +1,9 @@
|
||||
package liquid
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -63,3 +65,19 @@ func TestEngine_ParseAndRenderString_struct(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "hello", str)
|
||||
}
|
||||
|
||||
func BenchmarkEngine_Parse(b *testing.B) {
|
||||
engine := NewEngine()
|
||||
buf := new(bytes.Buffer)
|
||||
for i := 0; i < 1000; i++ {
|
||||
io.WriteString(buf, `if{% if true %}true{% elsif %}elsif{% else %}else{% endif %}`)
|
||||
io.WriteString(buf, `loop{% for item in array %}loop{% break %}{% endfor %}`)
|
||||
io.WriteString(buf, `case{% case value %}{% when a %}{% when b %{% endcase %}`)
|
||||
io.WriteString(buf, `expr{{ a and b }}{{ a add: b }}`)
|
||||
}
|
||||
s := buf.Bytes()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
engine.ParseTemplate(s)
|
||||
}
|
||||
}
|
||||
|
@ -95,3 +95,16 @@ func TestTemplate_Render_race(t *testing.T) {
|
||||
}
|
||||
wg2.Wait()
|
||||
}
|
||||
|
||||
func BenchmarkTemplate_Render(b *testing.B) {
|
||||
engine := NewEngine()
|
||||
bindings := Bindings{"a": "string value"}
|
||||
tpl, err := engine.ParseString(`{% for i in (1..1000) %}{% if i > 500 %}{{a}}{% else %}0{% endif %}{% endfor %}`)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
tpl.Render(bindings)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user