54 lines
856 B
Go
54 lines
856 B
Go
|
package arrayn
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/Pallinder/go-randomdata"
|
||
|
)
|
||
|
|
||
|
func TestCase1(t *testing.T) {
|
||
|
arr := NewWithCap(3, 3, 3, 3)
|
||
|
for i := 0; i < 52; i++ {
|
||
|
arr.Set(i, i)
|
||
|
}
|
||
|
|
||
|
t.Error(arr.Get(2))
|
||
|
t.Error(arr.Get(1))
|
||
|
t.Error(arr.Get(80))
|
||
|
}
|
||
|
|
||
|
func BenchmarkGoMap(b *testing.B) {
|
||
|
m := make(map[int]bool)
|
||
|
b.N = 50000000
|
||
|
b.StopTimer()
|
||
|
var l []int
|
||
|
for i := 0; i < b.N/10; i++ {
|
||
|
l = append(l, randomdata.Number(0, 100000000))
|
||
|
}
|
||
|
b.StartTimer()
|
||
|
for c := 0; c < 10; c++ {
|
||
|
for i := 0; i < b.N/10; i++ {
|
||
|
m[l[i]] = true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BenchmarkArrayNSet(b *testing.B) {
|
||
|
|
||
|
arr := NewWithCap(10, 10, 10, 10000)
|
||
|
b.N = 10000000
|
||
|
|
||
|
b.StopTimer()
|
||
|
var l []int
|
||
|
for i := 0; i < b.N/10; i++ {
|
||
|
l = append(l, randomdata.Number(0, 10000000))
|
||
|
}
|
||
|
b.StartTimer()
|
||
|
for c := 0; c < 10; c++ {
|
||
|
for i := 0; i < b.N/10; i++ {
|
||
|
arr.Set(l[i], i)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|