Files
littlefs/benches/bench_file.toml
T
Christopher Haster 238c2babe4 runners: bench: Added litmus flag, default to disabled
The litmus benches are really only intended for introspection/debugging/
cool plots/etc. They're interesting to poke around with and cover a wide
range of littlefs's data-structures, but are not very rigorous.

To make this more clear for new users, added a new litmus flag for
benches:

  litmus = true

This doesn't change anything about how the bench is run, but serves as a
marker to hint that the bench is intended for non-rigorous benchmarking.

---

In the makefile, litmus tests are disabled by default at runtime
(--no-litmus). This is to limit `make bench` to benches that are useful
for performance comparisons.

With --no-litmus at runtime, the litmus benches are at least compiled
into the bench_runner, which should hopefully encourage keeping them up
to date with code changes. Eventually we should also run them in CI, but
only to check for runtime errors.

Unlike our tests, we're not really worried about compile time at the
moment due to how few/small our benches are.
2026-03-09 22:54:31 -05:00

105 lines
3.0 KiB
TOML

# Simple file benchmark
after = ['bench_rbyd', 'bench_btree']
# helper for measuring disk usage
code = '''
#include "benches/bench_helpers.h"
'''
[cases.bench_file]
# 0 = in-order
# 1 = reversed-order
# 2 = random-order
# 3 = random-unaligned-order
defines.ORDER = 3
defines.SIZE = '1024*1024' # 1 MiB
defines.CHUNK = 64
defines.FLUSH = true # note if you don't flush, reads may end up writing
defines.SYNC = false
defines.STEP = 1
defines.SEED = 42
# set of probes to measure
# 0x1 => write
# 0x2 => read
# 0x4 => usage
defines.MASK = 0x7
# not the most rigorous
litmus = true
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = SEED;
// open our file
lfs3_file_t file;
lfs3_file_open(&lfs3, &file, "bench_file",
LFS3_O_RDWR | LFS3_O_CREAT | LFS3_O_EXCL) => 0;
for (lfs3_size_t i = 0; i < (SIZE+(CHUNK-1))/CHUNK; i++) {
lfs3_off_t i_
= (ORDER == 0)
? i*CHUNK
: (ORDER == 1)
? (((SIZE+(CHUNK-1))/CHUNK)-1-i)*CHUNK
: (ORDER == 2)
? (BENCH_PRNG(&prng) % ((SIZE+(CHUNK-1))/CHUNK)) * CHUNK
: BENCH_PRNG(&prng) % (lfs3_max(SIZE, CHUNK) - (CHUNK-1));
// measure a write
if ((MASK & 0x1) && (i+1) % STEP == 0) {
BENCH_START("write");
}
// seek to where we want to write
lfs3_file_seek(&lfs3, &file, i_, LFS3_SEEK_SET) => i_;
// write
uint8_t wbuf[CHUNK];
for (lfs3_size_t j = 0; j < CHUNK; j++) {
wbuf[j] = 'a' + (BENCH_PRNG(&prng) % 26);
}
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
// flush?
if (FLUSH) {
lfs3_file_flush(&lfs3, &file) => 0;
}
// sync?
if (SYNC) {
lfs3_file_sync(&lfs3, &file) => 0;
}
if ((MASK & 0x1) && (i+1) % STEP == 0) {
BENCH_STOP("write", i*CHUNK+CHUNK);
}
// measure a random chunk-sized read
if ((MASK & 0x2) && (i+1) % STEP == 0) {
BENCH_START("read");
// align to chunk?
lfs3_off_t i__ = (ORDER <= 2)
? (BENCH_PRNG(&prng)
% ((lfs3_file_size(&lfs3, &file)+(CHUNK-1))/CHUNK))
* CHUNK
: BENCH_PRNG(&prng)
% (lfs3_file_size(&lfs3, &file) - (CHUNK-1));
// seek to where we want to read
lfs3_file_seek(&lfs3, &file, i__, LFS3_SEEK_SET) => i__;
// read
uint8_t rbuf[CHUNK];
lfs3_file_read(&lfs3, &file, rbuf, CHUNK) => CHUNK;
BENCH_STOP("read", i*CHUNK+CHUNK);
}
// measure disk usage
if ((MASK & 0x4) && (i+1) % STEP == 0) {
uintmax_t usage = bench_helpers_usage(&lfs3);
BENCH_RESULT("usage", i*CHUNK+CHUNK, usage);
}
}
lfs3_file_close(&lfs3, &file) => 0;
lfs3_unmount(&lfs3) => 0;
'''