]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
transform/livereloadinject: Add benchmark
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 29 Oct 2023 16:50:55 +0000 (17:50 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 29 Oct 2023 16:50:55 +0000 (17:50 +0100)
transform/livereloadinject/livereloadinject_test.go

index d5cee79f8c4ed2610f74739078b3d7c3fd6840bd..cba2d383451e1677a17956ee861fbe2e337c18df 100644 (file)
@@ -15,6 +15,7 @@ package livereloadinject
 
 import (
        "bytes"
+       "io"
        "net/url"
        "strings"
        "testing"
@@ -70,3 +71,26 @@ func TestLiveReloadInject(t *testing.T) {
                c.Assert(apply("<h1>No match</h1>"), qt.Equals, "<h1>No match</h1>"+expectBase+warnScript)
        })
 }
+
+func BenchmarkLiveReloadInject(b *testing.B) {
+       s := `
+<html>
+<head>
+</head>
+<body>
+</body>
+</html>        
+`
+       in := strings.NewReader(s)
+       lrurl, err := url.Parse("http://localhost:1234/subpath")
+       if err != nil {
+               b.Fatalf("Parsing test URL failed")
+       }
+       tr := transform.New(New(*lrurl))
+
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               in.Seek(0, 0)
+               tr.Apply(io.Discard, in)
+       }
+}