diff options
| author | EuAndreh <eu@euandre.org> | 2026-06-12 09:19:28 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-06-12 09:19:28 -0300 |
| commit | 46fd0362bce11d709e5efe6d540358533985d363 (patch) | |
| tree | f77d2ed33c4f3fb6e85353e436efca4e19028f73 /tests/benchmarks/ranking-throughput/remembering.go | |
| parent | rm .tdrc COPYING (diff) | |
| download | remembering-46fd0362bce11d709e5efe6d540358533985d363.tar.gz remembering-46fd0362bce11d709e5efe6d540358533985d363.tar.xz | |
Rewrite remembering in Go
The shell pipeline (sed | sort | tee | awk | sort | cut | "$@"
plus the cut | uniq | awk profile rewrite) becomes a single static
binary with the same observable behaviour, pinned by the original
ranking.sh, signals.sh and cli-opts.sh suites, now aimed at
remembering.bin:
- the profile keeps the exact on-disk format, COUNT profile TEXT,
byte-sorted with new picks appended at 1 and offered-but-never-
picked entries persisted at 0;
- the menu stays count-descending with byte-order ties, stdin
alone defines what is offered, and duplicate profile lines sum
for ranking but collapse to the highest count on rewrite, as
sort | uniq -f1 did;
- the wrapped command's exit status is forwarded as-is (128+sig
for signal deaths), its stderr passes through, and an empty pick
learns nothing;
- the profile rewrite stays atomic via .tmp plus rename.
Per the house CLI conventions, -h/-V/--help/--version are gone
(the manpage is the documentation; bad options print the usage on
stderr and exit 2), and getopts-style attached option arguments
(-pNAME) are not accepted any more --- no script in the wild used
them.
The project layout follows rot: raw go tool compile/link Makefile,
mkdeps.sh-generated deps.mk, white-box unit suite, fuzz target
over the profile parse/serialize roundtrip, functional pick
roundtrip, a 1M-line ranking benchmark, and a single English
asciidoc manpage absorbing the old .5 page; the po4a/aux release
machinery goes away.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'tests/benchmarks/ranking-throughput/remembering.go')
| -rw-r--r-- | tests/benchmarks/ranking-throughput/remembering.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/benchmarks/ranking-throughput/remembering.go b/tests/benchmarks/ranking-throughput/remembering.go new file mode 100644 index 0000000..041eaeb --- /dev/null +++ b/tests/benchmarks/ranking-throughput/remembering.go @@ -0,0 +1,76 @@ +package remembering + +import ( + "flag" + "fmt" + "io" + "os" + "path/filepath" + "strings" +) + + + +var linesFlag = flag.Int( + "lines", + 1000000, + "The number of menu lines to rank", +) + +func MainTest() { + flag.Parse() + n := *linesFlag + + tmp, err := os.MkdirTemp("", "remembering-bench-") + if err != nil { + panic(err) + } + defer os.RemoveAll(tmp) + err = os.Setenv("XDG_DATA_HOME", tmp) + if err != nil { + panic(err) + } + + menu := strings.Builder{} + for i := 0; i < n; i++ { + fmt.Fprintf(&menu, "item-%07d\n", i) + } + + // half the items are already known, with spread counts + profile := strings.Builder{} + for i := 0; i < n; i += 2 { + fmt.Fprintf( + &profile, "%d profile item-%07d\n", + i%97, i, + ) + } + path, err := profilePath("bench") + if err != nil { + panic(err) + } + err = os.MkdirAll(filepath.Dir(path), 0755) + if err != nil { + panic(err) + } + err = os.WriteFile( + path, []byte(profile.String()), 0644, + ) + if err != nil { + panic(err) + } + + rc := run(envT{ + allArgs: []string{ + "remembering", "-p", "bench", + "--", "tail", "-n1", + }, + in: strings.NewReader(menu.String()), + out: io.Discard, + err: os.Stderr, + }) + if rc != 0 { + panic("ranking failed") + } + + fmt.Printf("ranked %d lines\n", n) +} |
