Skip to content

Commit

Permalink
Add JA4 benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
wi1dcard committed Mar 17, 2024
1 parent 2d8c796 commit 3504cc0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- run: |
go version
go get
- name: make test
- name: Go test and benchmark
run: |
echo '```' >> $GITHUB_STEP_SUMMARY
make test >> $GITHUB_STEP_SUMMARY
( make benchmark && make test ) | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
build:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ build_%:
PKG_LIST = $(shell go list ./... | grep -v github.com/wi1dcard/fingerproxy/pkg/http2)
test:
@go test -v $(PKG_LIST)

benchmark:
@go test -v $(PKG_LIST) -run=NONE -bench=^Benchmark -benchmem -count=3 -cpu=2
20 changes: 18 additions & 2 deletions pkg/ja4/ja4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func assertJA4(t *testing.T, hexClientHello string, expectedJA4 string) {
fp := JA4Fingerprint{}
err := fp.UnmarshalBytes(hexToBytes(t, hexClientHello), 't')
if err != nil {
t.Error(err)
t.Fatal(err)
}

str := fp.String()
if str != expectedJA4 {
t.Errorf("expected %s, actual %s", expectedJA4, str)
t.Fatalf("expected %s, actual %s", expectedJA4, str)
}
}

Expand All @@ -49,3 +49,19 @@ func TestMacCurl860(t *testing.T) {
"t13d1516h2_8daaf6152771_e5627efa2ab1",
)
}

var (
benchmarkClientHello = []byte{22, 3, 1, 2, 0, 1, 0, 1, 252, 3, 3, 69, 176, 233, 69, 101, 132, 70, 251, 152, 19, 108, 48, 225, 190, 130, 237, 75, 216, 30, 22, 211, 50, 185, 243, 49, 122, 85, 63, 203, 136, 228, 38, 32, 50, 119, 97, 53, 205, 42, 33, 61, 205, 147, 94, 233, 244, 113, 118, 141, 113, 77, 138, 158, 50, 146, 16, 46, 26, 46, 132, 15, 82, 100, 75, 1, 0, 32, 74, 74, 19, 1, 19, 2, 19, 3, 192, 43, 192, 47, 192, 44, 192, 48, 204, 169, 204, 168, 192, 19, 192, 20, 0, 156, 0, 157, 0, 47, 0, 53, 1, 0, 1, 147, 74, 74, 0, 0, 0, 0, 0, 25, 0, 23, 0, 0, 20, 108, 112, 116, 97, 103, 46, 108, 105, 118, 101, 112, 101, 114, 115, 111, 110, 46, 110, 101, 116, 0, 51, 0, 43, 0, 41, 26, 26, 0, 1, 0, 0, 29, 0, 32, 160, 161, 163, 83, 196, 153, 112, 74, 155, 86, 175, 119, 243, 248, 124, 253, 210, 135, 227, 48, 9, 237, 165, 79, 154, 185, 180, 63, 178, 245, 149, 99, 0, 16, 0, 14, 0, 12, 2, 104, 50, 8, 104, 116, 116, 112, 47, 49, 46, 49, 0, 23, 0, 0, 255, 1, 0, 1, 0, 0, 18, 0, 0, 0, 43, 0, 7, 6, 218, 218, 3, 4, 3, 3, 0, 13, 0, 18, 0, 16, 4, 3, 8, 4, 4, 1, 5, 3, 8, 5, 5, 1, 8, 6, 6, 1, 0, 10, 0, 10, 0, 8, 26, 26, 0, 29, 0, 23, 0, 24, 0, 45, 0, 2, 1, 1, 0, 5, 0, 5, 1, 0, 0, 0, 0, 0, 35, 0, 0, 0, 11, 0, 2, 1, 0, 68, 105, 0, 5, 0, 3, 2, 104, 50, 0, 27, 0, 3, 2, 0, 2, 234, 234, 0, 1, 0, 0, 21, 0, 195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
thisPreventsCompilerOptimization string
)

func BenchmarkJA4(b *testing.B) {
for n := 0; n < b.N; n++ {
fp := JA4Fingerprint{}
err := fp.UnmarshalBytes(benchmarkClientHello, 't')
if err != nil {
b.Fatal(err)
}
thisPreventsCompilerOptimization = fp.String()
}
}

0 comments on commit 3504cc0

Please sign in to comment.