mirror of https://github.com/dirtbags/moth.git
Add zipfile performance testing
This commit is contained in:
parent
430e44ce87
commit
431e1f00a7
|
@ -48,13 +48,13 @@ func main() {
|
|||
go state.Run(*refreshInterval)
|
||||
go puzzles.Run(*refreshInterval)
|
||||
|
||||
// Add some MIME extensions
|
||||
// Doing this avoids decompressing a mothball entry twice per request
|
||||
mime.AddExtensionType(".json", "application/json")
|
||||
mime.AddExtensionType(".zip", "application/zip")
|
||||
|
||||
http.HandleFunc("/", theme.staticHandler)
|
||||
|
||||
log.Printf("Listening on %s", *bindStr)
|
||||
log.Fatal(http.ListenAndServe(*bindStr, nil))
|
||||
// Add some MIME extensions
|
||||
// Doing this avoids decompressing a mothball entry twice per request
|
||||
mime.AddExtensionType(".json", "application/json")
|
||||
mime.AddExtensionType(".zip", "application/zip")
|
||||
|
||||
http.HandleFunc("/", theme.staticHandler)
|
||||
|
||||
log.Printf("Listening on %s", *bindStr)
|
||||
log.Fatal(http.ListenAndServe(*bindStr, nil))
|
||||
}
|
||||
|
|
|
@ -47,22 +47,22 @@ func TestState(t *testing.T) {
|
|||
if err := s.SetTeamName(teamId, "My Team"); err != nil {
|
||||
t.Errorf("Setting team name: %v", err)
|
||||
}
|
||||
|
||||
|
||||
category := "poot"
|
||||
points := 3928
|
||||
s.AwardPoints(teamId, category, points)
|
||||
s.Cleanup()
|
||||
|
||||
|
||||
pl = s.PointsLog()
|
||||
if len(pl) != 1 {
|
||||
t.Errorf("After awarding points, points log has length %d", len(pl))
|
||||
} else if (pl[0].TeamId != teamId) || (pl[0].Category != category) || (pl[0].Points != points) {
|
||||
t.Errorf("Incorrect logged award %v", pl)
|
||||
}
|
||||
|
||||
|
||||
fs.Remove("initialized")
|
||||
s.Cleanup()
|
||||
|
||||
|
||||
pl = s.PointsLog()
|
||||
if len(pl) != 0 {
|
||||
t.Errorf("After reinitialization, points log has length %d", len(pl))
|
||||
|
|
|
@ -18,14 +18,14 @@ func TestTheme(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(s.staticHandler)
|
||||
handler.ServeHTTP(rr, req)
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Errorf("Handler returned wrong code: %v", rr.Code)
|
||||
}
|
||||
|
||||
|
||||
if rr.Body.String() != "index" {
|
||||
t.Errorf("Handler returned wrong content: %v", rr.Body.String())
|
||||
}
|
||||
|
|
|
@ -5,10 +5,80 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestZipPerformance(t *testing.T) {
|
||||
// I get 4.8s for 10,000 reads
|
||||
if os.Getenv("BENCHMARK") == "" {
|
||||
return
|
||||
}
|
||||
|
||||
rng := rand.New(rand.NewSource(rand.Int63()))
|
||||
|
||||
tf, err := ioutil.TempFile("", "zipfs")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
|
||||
w := zip.NewWriter(tf)
|
||||
for i := 0; i < 100; i += 1 {
|
||||
fsize := 1000
|
||||
switch {
|
||||
case i % 10 == 0:
|
||||
fsize = 400000
|
||||
case i % 20 == 6:
|
||||
fsize = 5000000
|
||||
case i == 80:
|
||||
fsize = 1000000000
|
||||
}
|
||||
|
||||
f, err := w.Create(fmt.Sprintf("%d.bin", i))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
if _, err := io.CopyN(f, rng, int64(fsize)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
w.Close()
|
||||
|
||||
tfsize, err := tf.Seek(0, 2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
nReads := 10000
|
||||
for i := 0; i < 10000; i += 1 {
|
||||
r, err := zip.NewReader(tf, tfsize)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
filenum := rng.Intn(len(r.File))
|
||||
f, err := r.File[filenum].Open()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
buf, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log("Read file of size", len(buf))
|
||||
f.Close()
|
||||
}
|
||||
t.Log(nReads, "reads took", time.Since(startTime))
|
||||
t.Error("moo")
|
||||
}
|
||||
|
||||
func TestZipfs(t *testing.T) {
|
||||
tf, err := ioutil.TempFile("", "zipfs")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue