62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|||
|
|
// SPDX-License-Identifier: MIT
|
||
|
|
|
||
|
|
package io
|
||
|
|
|
||
|
|
// Benchmarks for the paths the coordinator's battery does not isolate.
|
||
|
|
// Every fixture is deterministic and built before the measured loop.
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
// BenchmarkWaveFITSBinaryTextCells measures the character-column decode
|
||
|
|
// alone: one 8A column of four thousand rows, the per-cell work the
|
||
|
|
// binary-table benchmark mixes with seven numeric columns.
|
||
|
|
func BenchmarkWaveFITSBinaryTextCells(b *testing.B) {
|
||
|
|
const rows = 4000
|
||
|
|
path := filepath.Join(b.TempDir(), "textcells.fits")
|
||
|
|
body := make([]byte, rows*8)
|
||
|
|
for r := range rows {
|
||
|
|
copy(body[r*8:], "star ")
|
||
|
|
}
|
||
|
|
cards := []string{
|
||
|
|
fitsStringCardRaw("XTENSION", "BINTABLE"),
|
||
|
|
fitsIntCard("BITPIX", 8),
|
||
|
|
fitsIntCard("NAXIS", 2),
|
||
|
|
fitsIntCard("NAXIS1", 8),
|
||
|
|
fitsIntCard("NAXIS2", rows),
|
||
|
|
fitsIntCard("PCOUNT", 0),
|
||
|
|
fitsIntCard("GCOUNT", 1),
|
||
|
|
fitsIntCard("TFIELDS", 1),
|
||
|
|
fitsStringCardRaw("TTYPE1", "STAR"),
|
||
|
|
fitsStringCardRaw("TFORM1", "8A"),
|
||
|
|
fitsEndCard(),
|
||
|
|
}
|
||
|
|
out := fitsAppendCards(nil, []string{
|
||
|
|
fitsBoolCard("SIMPLE", true),
|
||
|
|
fitsIntCard("BITPIX", 8),
|
||
|
|
fitsIntCard("NAXIS", 0),
|
||
|
|
fitsBoolCard("EXTEND", true),
|
||
|
|
fitsEndCard(),
|
||
|
|
})
|
||
|
|
out = fitsAppendCards(out, cards)
|
||
|
|
out = append(out, body...)
|
||
|
|
out = fitsAppendZeroPad(out)
|
||
|
|
if err := os.WriteFile(path, out, 0o644); err != nil {
|
||
|
|
b.Fatal(err)
|
||
|
|
}
|
||
|
|
b.ReportAllocs()
|
||
|
|
for b.Loop() {
|
||
|
|
table, err := LoadFITSTable(path)
|
||
|
|
if err != nil {
|
||
|
|
b.Fatal(err)
|
||
|
|
}
|
||
|
|
if table.Rows != rows || table.Text[0] == nil || table.Text[0][0] != "star" {
|
||
|
|
b.Fatalf("table came back as %s with %d rows", table.Kind, table.Rows)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|