You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
770 B

package ip2region
import (
"testing"
)
func BenchmarkBtreeSearch(B *testing.B) {
region, err := New("../ip2region.db ")
if err != nil {
B.Error(err)
}
for i := 0; i < B.N; i++ {
region.BtreeSearch("127.0.0.1")
}
}
func BenchmarkMemorySearch(B *testing.B) {
region, err := New("../ip2region.db ")
if err != nil {
B.Error(err)
}
for i := 0; i < B.N; i++ {
region.MemorySearch("127.0.0.1")
}
}
func BenchmarkBinarySearch(B *testing.B) {
region, err := New("../ip2region.db ")
if err != nil {
B.Error(err)
}
for i := 0; i < B.N; i++ {
region.BinarySearch("127.0.0.1")
}
}
func TestIp2long(t *testing.T) {
ip, err := ip2long("127.0.0.1")
if err != nil {
t.Error(err)
}
if ip != 2130706433 {
t.Error("result error")
}
t.Log(ip)
}