Skip to content

Commit

Permalink
Reduce performance test size for CI (#10)
Browse files Browse the repository at this point in the history
* Add --performance_test_size to go-kd/internal/perf test

* Update performance test docstring to include how to run test with full suite

* Update CI workflow
  • Loading branch information
minkezhang authored Aug 5, 2022
1 parent d6ab39c commit c3fac65
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
presubmit:
name: CI Tests
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- uses: actions/checkout@v2
Expand All @@ -25,4 +24,4 @@ jobs:
run: go vet github.com/downflux/go-kd/...

- name: Test github.com/downflux/go-kd
run: go test github.com/downflux/go-kd/... -run ^$ -bench . -benchmem -timeout=60m
run: go test github.com/downflux/go-kd/... -run ^$ -bench . -benchmem -timeout=10m
44 changes: 33 additions & 11 deletions internal/perf/perf_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// Package perf runs a suite of perf tests.
//
// CI tests are run against a smaller set of configurations in order to fit into
// computational time constraints. To run the full set of tests (which make take
// up to an hour), run
//
// go test github.com/downflux/go-kd/internal/perf \
// -bench . -benchmem -timeout=60m \
// -args -performance_test_size=large
package perf

import (
"flag"
"fmt"
"os"
"testing"
"unsafe"

Expand All @@ -17,6 +28,17 @@ import (
ckd "github.com/downflux/go-kd/container/kd"
)

var (
SuiteSize = util.SizeSmall
)

func TestMain(m *testing.M) {
flag.Var(&SuiteSize, "performance_test_size", "performance test size, one of (small | large)")
flag.Parse()

os.Exit(m.Run())
}

func BenchmarkNew(b *testing.B) {
type config struct {
name string
Expand All @@ -30,15 +52,15 @@ func BenchmarkNew(b *testing.B) {
}

var configs []config
for _, k := range util.BenchmarkKRange {
for _, n := range util.BenchmarkNRange {
for _, k := range util.BenchmarkKRange(SuiteSize) {
for _, n := range util.BenchmarkNRange(SuiteSize) {
configs = append(configs, config{
name: fmt.Sprintf("kyroy/K=%v/N=%v", k, n),
k: k,
n: n,
kyroy: true,
})
for _, size := range util.BenchmarkSizeRange {
for _, size := range util.BenchmarkSizeRange(SuiteSize) {
configs = append(configs, config{
name: fmt.Sprintf("Real/K=%v/N=%v/LeafSize=%v", k, n, size),
k: k,
Expand Down Expand Up @@ -81,8 +103,8 @@ func BenchmarkKNN(b *testing.B) {
}

var configs []config
for _, k := range util.BenchmarkKRange {
for _, n := range util.BenchmarkNRange {
for _, k := range util.BenchmarkKRange(SuiteSize) {
for _, n := range util.BenchmarkNRange(SuiteSize) {
ps := util.Generate(n, k)

// Brute force approach sorts all data, meaning that the
Expand All @@ -94,7 +116,7 @@ func BenchmarkKNN(b *testing.B) {
knn: n,
})

for _, f := range util.BenchmarkFRange {
for _, f := range util.BenchmarkFRange(SuiteSize) {
knn := int(float64(n) * f)

// kyroy implementation does not take a
Expand All @@ -106,7 +128,7 @@ func BenchmarkKNN(b *testing.B) {
knn: knn,
})

for _, size := range util.BenchmarkSizeRange {
for _, size := range util.BenchmarkSizeRange(SuiteSize) {
configs = append(configs, config{
name: fmt.Sprintf("Real/K=%v/N=%v/LeafSize=%v/KNN=%v", k, n, size, f),
t: (*ckd.KD[*mock.P])(unsafe.Pointer(
Expand Down Expand Up @@ -142,8 +164,8 @@ func BenchmarkRangeSearch(b *testing.B) {
}

var configs []config
for _, k := range util.BenchmarkKRange {
for _, n := range util.BenchmarkNRange {
for _, k := range util.BenchmarkKRange(SuiteSize) {
for _, n := range util.BenchmarkNRange(SuiteSize) {
ps := util.Generate(n, k)

// Brute force approach sorts all data, meaning that the
Expand All @@ -154,7 +176,7 @@ func BenchmarkRangeSearch(b *testing.B) {
q: util.RH(k, 1),
})

for _, f := range util.BenchmarkFRange {
for _, f := range util.BenchmarkFRange(SuiteSize) {
q := util.RH(k, f)

// kyroy implementation does not take a
Expand All @@ -165,7 +187,7 @@ func BenchmarkRangeSearch(b *testing.B) {
q: q,
})

for _, size := range util.BenchmarkSizeRange {
for _, size := range util.BenchmarkSizeRange(SuiteSize) {
configs = append(configs, config{
name: fmt.Sprintf("Real/K=%v/N=%v/LeafSize=%v/Coverage=%v", k, n, size, f),
t: (*ckd.KD[*mock.P])(unsafe.Pointer(
Expand Down
58 changes: 53 additions & 5 deletions internal/perf/util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"fmt"
"math"
"math/rand"
"runtime"
Expand All @@ -14,17 +15,64 @@ import (
)

var (
BenchmarkKRange = []vector.D{2, 16, 128}
BenchmarkNRange = []int{1e3, 1e4, 1e6}
BenchmarkSizeRange = []int{1, 32, 512}
BenchmarkFRange = []float64{0.05, 0.1, 0.25}

KRange = []vector.D{2}
NRange = []int{1e3}
SizeRange = []int{1, 16}
FRange = []float64{0.05}
)

type PerfTestSize int

const (
SizeUnknown PerfTestSize = iota
SizeSmall
SizeLarge
)

func (s *PerfTestSize) String() string {
return map[PerfTestSize]string{
SizeSmall: "small",
SizeLarge: "large",
}[*s]
}

func (s *PerfTestSize) Set(v string) error {
size, ok := map[string]PerfTestSize{
"small": SizeSmall,
"large": SizeLarge,
}[v]
if !ok {
return fmt.Errorf("invalid test size value: %v", v)
}
*s = size
return nil
}

func BenchmarkFRange(s PerfTestSize) []float64 {
return map[PerfTestSize][]float64{
SizeSmall: []float64{0.05},
SizeLarge: []float64{0.05, 0.1, 0.25},
}[s]
}

func BenchmarkSizeRange(s PerfTestSize) []int {
return []int{1, 32, 512}
}

func BenchmarkNRange(s PerfTestSize) []int {
return map[PerfTestSize][]int{
SizeSmall: []int{1e3, 1e4},
SizeLarge: []int{1e3, 1e4, 1e6},
}[s]
}

func BenchmarkKRange(s PerfTestSize) []vector.D {
return map[PerfTestSize][]vector.D{
SizeSmall: []vector.D{2, 16},
SizeLarge: []vector.D{2, 16, 128},
}[s]
}

func TrivialFilter(p *mock.P) bool { return true }

// Transformer sorts a list of points.
Expand Down
10 changes: 10 additions & 0 deletions internal/perf/util/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package util

import (
"flag"
)

var (
s = SizeSmall
_ flag.Value = &s
)

0 comments on commit c3fac65

Please sign in to comment.