github.com/agnivade/pgm@v0.0.0-20210528073050-e2df0d9cb72d/benchmark_test.go (about) 1 package pgm 2 3 import ( 4 "bufio" 5 "fmt" 6 "math" 7 "os" 8 "strconv" 9 "testing" 10 "time" 11 ) 12 13 func BenchmarkIndex(b *testing.B) { 14 // read file 15 // use TestGendata to generate corpus. 16 f, err := os.Open("testdata/sorted.txt") 17 if err != nil { 18 b.Error(err) 19 } 20 21 data := make([]float64, 0, 1024) 22 scanner := bufio.NewScanner(f) 23 for scanner.Scan() { 24 res, err := strconv.ParseFloat(scanner.Text(), 64) 25 if err != nil { 26 b.Error(err) 27 } 28 data = append(data, res) 29 } 30 31 ind := NewIndex(data, 128) 32 for _, level := range ind.levels { 33 fmt.Println(level) 34 } 35 36 now := time.Now() 37 pos, err := ind.Search(1471031908028) 38 if err != nil { 39 b.Error(err) 40 } 41 b.Log(int(math.Round(data[pos.Lo])), int(math.Round(data[pos.Hi])), time.Since(now)) 42 43 // pos, err = ind.Search(1471031908020) 44 // if err != nil { 45 // b.Error(err) 46 // } 47 // b.Log(int(math.Round(data[pos.Lo])), int(math.Round(data[pos.Hi]))) 48 49 // pos, err = ind.Search(1471031908030) 50 // if err != nil { 51 // b.Error(err) 52 // } 53 // b.Log(int(math.Round(data[pos.Lo])), int(math.Round(data[pos.Hi]))) 54 }