Skip to content

Commit

Permalink
ci: benchmark grid
Browse files Browse the repository at this point in the history
  • Loading branch information
scorix committed Nov 19, 2024
1 parent 4276f0f commit 028c018
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pkg/geo/grids/grid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func runGridTests(t *testing.T, grid grids.Grid, tests []gridTestCase) {
}
}

func benchGridTests(b *testing.B, grid grids.Grid, tests []gridTestCase) {
for i := 0; i < b.N; i++ {
for _, tt := range tests {
grids.GridIndex(grid, tt.lat, tt.lon)
}
}
}

var defaultRegularLatLonGridTests = []gridTestCase{
// 网格点精确匹配
{name: "North Pole", lat: 90.0, lon: 0.0, expectedIdx: 0, gridLat: 90.0, gridLon: 0.0},
Expand Down Expand Up @@ -614,3 +622,71 @@ func TestRegularGaussian_ConsecutiveJOppositeRowsScanMode(t *testing.T) {

runGridTests(t, grid, consecutiveJOppositeRowsRegularGaussianGridTests)
}

func BenchmarkGridIndex(b *testing.B) {
b.Run("LatLon 0p25", func(b *testing.B) {
grid := latlon.NewLatLonGrid(-90, 90, 0.0, 359.75, 0.25, 0.25)

for i := 0; i < b.N; i++ {
grids.GridIndex(grid, 88.572169, 0.0)
}
})

b.Run("LatLon 0p16", func(b *testing.B) {
grid := latlon.NewLatLonGrid(-90, 90, 0.0, 359.84, 0.16, 0.16)

for i := 0; i < b.N; i++ {
grids.GridIndex(grid, 88.572169, 0.0)
}
})

b.Run("Gaussian F48", func(b *testing.B) {
grid := gaussian.NewRegular(48)

for i := 0; i < b.N; i++ {
grids.GridIndex(grid, 88.572169, 0.0)
}
})

b.Run("Gaussian F768", func(b *testing.B) {
grid := gaussian.NewRegular(768)

for i := 0; i < b.N; i++ {
grids.GridIndex(grid, 88.572169, 0.0)
}
})
}

func BenchmarkGridPoint(b *testing.B) {
b.Run("LatLon 0p25", func(b *testing.B) {
grid := latlon.NewLatLonGrid(-90, 90, 0.0, 359.75, 0.25, 0.25)

for i := 0; i < b.N; i++ {
grids.GridPoint(grid, i%grid.Size())
}
})

b.Run("LatLon 0p16", func(b *testing.B) {
grid := latlon.NewLatLonGrid(-90, 90, 0.0, 359.84, 0.16, 0.16)

for i := 0; i < b.N; i++ {
grids.GridPoint(grid, i%grid.Size())
}
})

b.Run("Gaussian F48", func(b *testing.B) {
grid := gaussian.NewRegular(48)

for i := 0; i < b.N; i++ {
grids.GridPoint(grid, i%grid.Size())
}
})

b.Run("Gaussian F768", func(b *testing.B) {
grid := gaussian.NewRegular(768)

for i := 0; i < b.N; i++ {
grids.GridPoint(grid, i%grid.Size())
}
})
}

0 comments on commit 028c018

Please sign in to comment.