package model
import (
"os"
"path/filepath"
"testing"
)
func loadLyricFixture(b *testing.B, name string) []byte {
b.Helper()
contents, err := os.ReadFile(filepath.Join("..", "tests", "fixtures", "lyrics", name))
if err != nil {
b.Fatal(err)
}
return contents
}
func benchmarkParse(b *testing.B, suffix, fixture string) {
contents := loadLyricFixture(b, fixture)
b.ReportAllocs()
b.SetBytes(int64(len(contents)))
for b.Loop() {
if _, err := ParseLyrics(b.Context(), suffix, "eng", contents); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseLyrics_LRC(b *testing.B) { benchmarkParse(b, ".lrc", "auld-lang-syne.lrc") }
func BenchmarkParseLyrics_Plain(b *testing.B) { benchmarkParse(b, ".txt", "auld-lang-syne.txt") }
func BenchmarkParseLyrics_EnhancedLRC(b *testing.B) { benchmarkParse(b, ".lrc", "auld-lang-syne.elrc") }
func BenchmarkParseLyrics_SRT(b *testing.B) { benchmarkParse(b, ".srt", "auld-lang-syne.srt") }
func BenchmarkParseLyrics_TTML(b *testing.B) { benchmarkParse(b, ".ttml", "auld-lang-syne.ttml") }
func BenchmarkParseLyrics_YAML(b *testing.B) { benchmarkParse(b, ".yaml", "auld-lang-syne.yaml") }
func BenchmarkParseLyrics_SniffTTML(b *testing.B) { benchmarkParse(b, "", "auld-lang-syne.ttml") }
func BenchmarkParseLyrics_SniffSRT(b *testing.B) { benchmarkParse(b, "", "auld-lang-syne.srt") }
func BenchmarkParseLyrics_SniffYAML(b *testing.B) { benchmarkParse(b, "", "auld-lang-syne.yaml") }
func BenchmarkParseLyrics_SniffLRC(b *testing.B) { benchmarkParse(b, "", "auld-lang-syne.lrc") }
func BenchmarkParseLyrics_SniffPlain(b *testing.B) { benchmarkParse(b, "", "auld-lang-syne.txt") }