summaryrefslogtreecommitdiff
path: root/search/search_test.go
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-21 20:54:55 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-21 20:54:55 +0000
commite80cca57e072cf902f3e91ebe05f1ab8fbd55af8 (patch)
tree9a9abe1f49698a8c36594afcc439af5038d2727f /search/search_test.go
parent7815c3d006b64d5a6a6664e7c2c96c9c27f29c45 (diff)
add gomap for search
Diffstat (limited to 'search/search_test.go')
-rw-r--r--search/search_test.go37
1 files changed, 24 insertions, 13 deletions
diff --git a/search/search_test.go b/search/search_test.go
index 09ed906..ec977cc 100644
--- a/search/search_test.go
+++ b/search/search_test.go
@@ -10,9 +10,7 @@ import (
const factor int = 10
const minLength int = 1
-const maxLength int = 10
-
-//const maxLength int = 10000
+const maxLength int = 10000
// Store results here to avoid compiler optimizations
var benchResult int
@@ -29,6 +27,18 @@ func TestBST(t *testing.T) {
}
}
+func TestRedBlackBST(t *testing.T) {
+ for i := minLength; i <= maxLength; i *= factor {
+ test(NewRedBlackBST(), i, t)
+ }
+}
+
+func TestGoMap(t *testing.T) {
+ for i := minLength; i <= maxLength; i *= factor {
+ test(NewGoMap(), i, t)
+ }
+}
+
func test(s Put, l int, t *testing.T) {
keys := ds.NewRandomArrayList(l, l)
randoms := ds.NewRandomArrayList(l, -1)
@@ -41,10 +51,10 @@ func test(s Put, l int, t *testing.T) {
case del:
defer delete(mapping, key)
val, err = s.Del(key)
- t.Log("Del", key, val, err)
+ //t.Log("Del", key, val, err)
default:
val, err = s.Get(key)
- t.Log("Get", key, val, err)
+ //t.Log("Get", key, val, err)
}
if mVal, ok := mapping[key]; ok {
@@ -72,14 +82,14 @@ func test(s Put, l int, t *testing.T) {
testGet(key)
}
- t.Log("Put random key-values", l)
+ //t.Log("Put random key-values", l)
var prevKey int
for _, key := range sort.Shuffle(keys) {
testPut(key, randoms[key])
testGet(prevKey)
prevKey = key
}
- t.Log("Del random key-values", l)
+ //t.Log("Del random key-values", l)
for _, key := range sort.Shuffle(keys) {
testDel(key)
testGet(prevKey)
@@ -90,12 +100,6 @@ func test(s Put, l int, t *testing.T) {
}
}
-func TestRedBlackBST(t *testing.T) {
- for i := minLength; i <= maxLength; i *= factor {
- test(NewRedBlackBST(), i, t)
- }
-}
-
func BenchmarkElementary(t *testing.B) {
s := NewElementary()
for i := minLength; i <= maxLength; i *= factor {
@@ -117,6 +121,13 @@ func BenchmarkRedBlackBST(t *testing.B) {
}
}
+func BenchmarkGoMap(t *testing.B) {
+ s := NewGoMap()
+ for i := minLength; i <= maxLength; i *= factor {
+ benchmark(s, i, t)
+ }
+}
+
func benchmark(s Put, l int, b *testing.B) {
list := ds.NewRandomArrayList(l, -1)