Files
tensor/internal/core/misc_bench_test.go
petrbalvin af4ee19703
Release / gates (push) Successful in 4m38s
Test / test (push) Successful in 5m16s
Release / release (push) Successful in 35s
feat: initial release
Assisted-by: GLM 5.3 Flash
2026-09-03 10:00:00 +02:00

81 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: MIT
package core
import "testing"
// Miscellaneous bulk-path benchmarks: the generator fills, the sort
// family and the bilinear 2-D interpolation, at sizes where their
// inner loops dominate.
func BenchmarkGeneratorFloats1M(b *testing.B) {
g := NewGenerator(42)
b.ReportAllocs()
for b.Loop() {
if _, err := Floats(g, 1<<20); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkGeneratorNormal1M(b *testing.B) {
g := NewGenerator(42)
b.ReportAllocs()
for b.Loop() {
if _, err := Normal(g, 1<<20, 0, 1); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkSort1M(b *testing.B) {
a, _ := FromFloats(make([]float64, 1<<20), 1<<20)
g := NewGenerator(7)
src, _ := Floats(g, 1<<20)
copy(a.RawFloats(), src.RawFloats())
b.ResetTimer()
b.ReportAllocs()
for b.Loop() {
if _, err := Sort(a); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkArgSort1M(b *testing.B) {
a, _ := FromFloats(make([]float64, 1<<20), 1<<20)
g := NewGenerator(7)
src, _ := Floats(g, 1<<20)
copy(a.RawFloats(), src.RawFloats())
b.ResetTimer()
b.ReportAllocs()
for b.Loop() {
if _, err := ArgSort(a); err != nil {
b.Fatal(err)
}
}
}
// BenchmarkInterp2D samples one million bilinear queries against a
// 1024×1024 grid.
func BenchmarkInterp2D(b *testing.B) {
grid, _ := FromFloats(make([]float64, 1024*1024), 1024, 1024)
for i := range grid.RawFloats() {
grid.RawFloats()[i] = float64(i%97) / 97
}
n := 1 << 20
xs, _ := FromFloats(make([]float64, n), n)
ys, _ := FromFloats(make([]float64, n), n)
for i := range n {
xs.RawFloats()[i] = float64(i%1023) + 0.5
ys.RawFloats()[i] = float64((i*7)%1023) + 0.25
}
b.ReportAllocs()
for b.Loop() {
if _, err := Interpolate2D(grid, xs, ys, 0, 0, 1, 1); err != nil {
b.Fatal(err)
}
}
}