-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9751435
commit b76f75a
Showing
6 changed files
with
792 additions
and
958 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,30 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func BenchmarkList(b *testing.B) { | ||
const N = 10000 | ||
b.Run("lpush", func(b *testing.B) { | ||
ls := New() | ||
for i := 0; i < b.N; i++ { | ||
ls.LPush(genKey(i)) | ||
} | ||
}) | ||
b.Run("rpush", func(b *testing.B) { | ||
ls := New() | ||
for i := 0; i < b.N; i++ { | ||
ls.RPush(genKey(i)) | ||
} | ||
}) | ||
b.Run("lpop", func(b *testing.B) { | ||
ls := genList(0, b.N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.LPop() | ||
} | ||
}) | ||
b.Run("rpop", func(b *testing.B) { | ||
ls := genList(0, b.N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.RPop() | ||
} | ||
}) | ||
b.Run("index", func(b *testing.B) { | ||
ls := genList(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Index(i % N) | ||
} | ||
}) | ||
b.Run("set", func(b *testing.B) { | ||
ls := genList(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Set(i%N, genKey(N-i)) | ||
} | ||
}) | ||
b.Run("range", func(b *testing.B) { | ||
ls := genList(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Range(0, -1, func(s []byte) (stop bool) { | ||
return false | ||
}) | ||
} | ||
}) | ||
b.Run("revrange", func(b *testing.B) { | ||
ls := genList(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.RevRange(0, -1, func(s []byte) (stop bool) { | ||
return false | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkListPack(b *testing.B) { | ||
const N = 1000 | ||
b.Run("set/same-len", func(b *testing.B) { | ||
ls := genListPack(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Set(i%N, fmt.Sprintf("%08x", i)) | ||
} | ||
}) | ||
b.Run("set/less-len", func(b *testing.B) { | ||
b.Run("next", func(b *testing.B) { | ||
ls := genListPack(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Set(i%N, fmt.Sprintf("%07x", i)) | ||
it := ls.NewIterator() | ||
for i := 0; i < N; i++ { | ||
it.Next() | ||
} | ||
} | ||
}) | ||
b.Run("set/great-len", func(b *testing.B) { | ||
b.Run("prev", func(b *testing.B) { | ||
ls := genListPack(0, N) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
ls.Set(i%N, fmt.Sprintf("%09x", i)) | ||
it := ls.NewIterator() | ||
it.SeekEnd() | ||
for i := 0; i < N; i++ { | ||
it.Prev() | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.