Add some benchmarks

This commit is contained in:
Jakob Borg 2014-12-30 09:07:49 +01:00
parent b753f01ac1
commit 8f72ae9da2

View File

@ -72,7 +72,7 @@ func TestJobQueue(t *testing.T) {
}
}
if len(q.progress) > 0 || len(q.lookup) != 4 || q.queued.Len() != 4 {
if len(q.progress) > 0 || q.queued.Len() != 4 {
t.Fatal("Wrong length")
}
@ -106,7 +106,7 @@ func TestJobQueue(t *testing.T) {
}
}
if len(q.progress) != 4 || q.Pop() != nil || len(q.lookup) != 0 {
if len(q.progress) != 4 || q.Pop() != nil {
t.Fatal("Wrong length")
}
@ -116,7 +116,7 @@ func TestJobQueue(t *testing.T) {
q.Done(f4)
q.Done(f5) // Does not exist
if len(q.progress) != 0 || q.Pop() != nil || len(q.lookup) != 0 {
if len(q.progress) != 0 || q.Pop() != nil {
t.Fatal("Wrong length")
}
@ -131,3 +131,76 @@ func TestJobQueue(t *testing.T) {
t.Fatal("Wrong length")
}
}
/*
func BenchmarkJobQueuePush(b *testing.B) {
files := genFiles(b.N)
q := NewJobQueue()
b.ResetTimer()
for i := 0; i < b.N; i++ {
q.Push(&files[i])
}
}
func BenchmarkJobQueuePop(b *testing.B) {
files := genFiles(b.N)
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
q.Pop()
}
}
func BenchmarkJobQueuePopDone(b *testing.B) {
files := genFiles(b.N)
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
n := q.Pop()
q.Done(n)
}
}
*/
func BenchmarkJobQueueBump(b *testing.B) {
files := genFiles(b.N)
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
q.Bump(files[i].Name)
}
}
func BenchmarkJobQueuePushPopDone10k(b *testing.B) {
files := genFiles(10000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
}
for range files {
n := q.Pop()
q.Done(n)
}
}
}