splitTunnel_test.go 669 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package psiphon
  2. import (
  3. "encoding/binary"
  4. "io/ioutil"
  5. "math/rand"
  6. "net"
  7. "testing"
  8. )
  9. var netList networkList
  10. var isLocalAddr bool
  11. func Benchmark_NewNetworkList(b *testing.B) {
  12. routesData, err := ioutil.ReadFile("test_routes.dat")
  13. if err != nil {
  14. b.Skipf("can't load test routes file: %s", err)
  15. }
  16. for n := 0; n < b.N; n++ {
  17. netList, _ = NewNetworkList(routesData)
  18. }
  19. }
  20. func Benchmark_containsRandomAddr(b *testing.B) {
  21. if netList == nil {
  22. b.Skipf("no test routes file")
  23. }
  24. rand.Seed(0)
  25. for n := 0; n < b.N; n++ {
  26. ip := make([]byte, 4)
  27. binary.BigEndian.PutUint32(ip, rand.Uint32())
  28. isLocalAddr = netList.ContainsIpAddress(net.IP(ip))
  29. }
  30. }