GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Add benchmark for IsCached.

Thanks to Cecylia for questioning whether the cache lookup mechanism is
fast enough:
ecc6e048 (comment 2709958)
parent 4d76e010
...@@ -2,8 +2,10 @@ package main ...@@ -2,8 +2,10 @@ package main
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"net" "net"
"os" "os"
"testing" "testing"
...@@ -107,6 +109,30 @@ func TestCacheExpiration(t *testing.T) { ...@@ -107,6 +109,30 @@ func TestCacheExpiration(t *testing.T) {
} }
} }
func BenchmarkIsCached(b *testing.B) {
getRandAddrPort := func() string {
return fmt.Sprintf("%d.%d.%d.%d:%d",
rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(65536))
}
getRandError := func() error {
errors := []error{nil, errors.New("censorship"), errors.New("no censorship")}
return errors[rand.Intn(len(errors))]
}
numCacheEntries := 10000
cache := make(TestCache)
for i := 0; i < numCacheEntries; i++ {
cache.AddEntry(getRandAddrPort(), getRandError())
}
// How long does it take to iterate over numCacheEntries cache entries?
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.IsCached("invalid bridge line")
}
}
func TestCacheSerialisation(t *testing.T) { func TestCacheSerialisation(t *testing.T) {
cache := make(TestCache) cache := make(TestCache)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment