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.

Unverified Commit 471ab071 authored by Philipp Winter's avatar Philipp Winter
Browse files

Add benchmark for IsCached.

Thanks to Cecylia for questioning whether the cache lookup mechanism is
fast enough:
tpo/anti-censorship/bridgestrap@ecc6e048 (comment 2709958)
parent 4d76e010
......@@ -2,8 +2,10 @@ package main
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
"testing"
......@@ -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) {
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