Skip to content

Commit

Permalink
test: add benchmark of source probe
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Apr 25, 2021
1 parent 1c0b430 commit 6794616
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions probe/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package probe_test

import (
"context"
"fmt"
"net/url"
"os"
"regexp"
"testing"
"time"
Expand Down Expand Up @@ -92,3 +95,27 @@ func TestSource(t *testing.T) {
})
}
}

func BenchmarkSource_load(b *testing.B) {
for _, n := range []int{10, 25, 50, 75, 100, 250, 500, 750, 1000} {
b.Run(fmt.Sprint(n), func(b *testing.B) {
f, err := os.CreateTemp("", "ayd-test-*-list.txt")
if err != nil {
b.Fatalf("failed to create test file: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())

for i := 0; i < n; i++ {
fmt.Fprintf(f, "ping:host-%d\n", i)
}

target := &url.URL{Scheme: "source", Opaque: f.Name()}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = probe.NewSourceProbe(target)
}
})
}
}

0 comments on commit 6794616

Please sign in to comment.