MCPcopy Index your code
hub / github.com/tailscale/tailscale / BenchmarkFilter

Function BenchmarkFilter

wgengine/filter/filter_test.go:334–378  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

332}
333
334func BenchmarkFilter(b *testing.B) {
335 tcp4Packet := raw4(ipproto.TCP, "8.1.1.1", "1.2.3.4", 999, 22, 0)
336 udp4Packet := raw4(ipproto.UDP, "8.1.1.1", "1.2.3.4", 999, 22, 0)
337 icmp4Packet := raw4(ipproto.ICMPv4, "8.1.1.1", "1.2.3.4", 0, 0, 0)
338
339 tcp6Packet := raw6(ipproto.TCP, "::1", "2001::1", 999, 22, 0)
340 udp6Packet := raw6(ipproto.UDP, "::1", "2001::1", 999, 22, 0)
341 icmp6Packet := raw6(ipproto.ICMPv6, "::1", "2001::1", 0, 0, 0)
342
343 benches := []struct {
344 name string
345 dir direction
346 packet []byte
347 }{
348 // Non-SYN TCP and ICMP have similar code paths in and out.
349 {"icmp4", in, icmp4Packet},
350 {"tcp4_syn_in", in, tcp4Packet},
351 {"tcp4_syn_out", out, tcp4Packet},
352 {"udp4_in", in, udp4Packet},
353 {"udp4_out", out, udp4Packet},
354 {"icmp6", in, icmp6Packet},
355 {"tcp6_syn_in", in, tcp6Packet},
356 {"tcp6_syn_out", out, tcp6Packet},
357 {"udp6_in", in, udp6Packet},
358 {"udp6_out", out, udp6Packet},
359 }
360
361 for _, bench := range benches {
362 b.Run(bench.name, func(b *testing.B) {
363 acl := newFilter(b.Logf)
364 b.ReportAllocs()
365 b.ResetTimer()
366 for range b.N {
367 q := &packet.Parsed{}
368 q.Decode(bench.packet)
369 // This branch seems to have no measurable impact on performance.
370 if bench.dir == in {
371 acl.RunIn(q, 0)
372 } else {
373 acl.RunOut(q, 0)
374 }
375 }
376 })
377 }
378}
379
380func TestPreFilter(t *testing.T) {
381 packets := []struct {

Callers

nothing calls this directly

Calls 7

DecodeMethod · 0.95
raw4Function · 0.85
raw6Function · 0.85
newFilterFunction · 0.85
RunInMethod · 0.80
RunOutMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…