From ed45a0a8db7dc4d3a0dcdab02c103e2be4dd8b9c Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 30 Oct 2025 11:08:19 -0700 Subject: Add benchmark --- ccl_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'ccl_test.go') diff --git a/ccl_test.go b/ccl_test.go index f96e993..628009d 100644 --- a/ccl_test.go +++ b/ccl_test.go @@ -623,3 +623,60 @@ func ExampleUnmarshal() { // Output: // 301 https://$host$request_uri } + +func BenchmarkLex(b *testing.B) { + msg := []byte(` + # This is a comment + string: 'asdf\n' # comment end of line + string2: "asdf\n" + int: 10 + float: 10.5e13 + bool: true + bool2: false + message { field: 10 } + repeated: [1, 2, 3] + repeated: 4 + repeated: [5, 6] + `) + for b.Loop() { + for _, err := range tokens(msg) { + if err != nil { + b.Fatal(err) + } + } + } +} + +func BenchmarkParse(b *testing.B) { + msg := []byte(` + # This is a comment + string: 'asdf\n' # comment end of line + string2: "asdf\n" + int: 10 + float: 10.5e13 + bool: true + bool2: false + message { field: 10 } + repeated: [1, 2, 3] + repeated: 4 + repeated: [5, 6] + `) + type message struct { + String string `ccl:"string"` + String2 string `ccl:"string2"` + Int int `ccl:"int"` + Float float64 `ccl:"float"` + Bool bool `ccl:"bool"` + Bool2 bool `ccl:"bool2"` + Message struct { + Field int `ccl:"field"` + } `ccl:"message"` + Repeated []int `ccl:"repeated"` + } + for b.Loop() { + var m message + if err := Unmarshal(msg, &m); err != nil { + b.Fatal(err) + } + } +} -- cgit v1.3.1