@@ -27,10 +27,12 @@ import (
2727 "path/filepath"
2828 "regexp"
2929 "strconv"
30+ "strings"
3031 "testing"
3132 "time"
3233
3334 "github.com/stretchr/testify/assert"
35+ "github.com/stretchr/testify/require"
3436)
3537
3638var update = flag .Bool ("update" , false , "update .golden files" )
@@ -319,6 +321,30 @@ func BenchmarkParseAuditHeaderRegex(b *testing.B) {
319321 }
320322}
321323
324+ func BenchmarkParseLogLine (b * testing.B ) {
325+ // Build corpus of valid messages from the test data.
326+ files , err := filepath .Glob ("testdata/*.log" )
327+ require .NoError (b , err )
328+ var msgs []string
329+ for _ , f := range files {
330+ data , err := ioutil .ReadFile (f )
331+ require .NoError (b , err )
332+ for _ , line := range strings .Split (strings .TrimSpace (string (data )), "\n " ) {
333+ if _ , err = ParseLogLine (line ); err == nil {
334+ msgs = append (msgs , line )
335+ }
336+ }
337+ }
338+
339+ b .ResetTimer ()
340+ for i := 0 ; i < b .N ; i ++ {
341+ msg := msgs [i % len (msgs )]
342+ if _ , err = ParseLogLine (msg ); err != nil {
343+ b .Fatal (err )
344+ }
345+ }
346+ }
347+
322348// ExampleParseLogLine demonstrates parsing a log line from auditd and shows
323349// what the parsed data looks like.
324350func ExampleParseLogLine () {
0 commit comments