Files
littlefs/benches/b2_btree.toml
T
Christopher Haster 2fe2078f50 Renamed tests/benches such that order is logical
It doesn't make sense to test more complex logic, such as t2_btree.toml,
when the logic it is built on, t1_rbyd.toml, does not past testing. The
test runner already guarantees a consistent lexicographic order, so all
we need to do is renamed these from test_* -> tn_*.

Note, if we every have more than 10 tests, we will need to bump up the
number of digits for all tests, so t1_rbyd.toml -> t01_rbyd.toml. This
is the main downside of lexicographic ordering. But we'll cross that
bridge when we get to it.
2023-06-30 16:37:23 -05:00

112 lines
3.0 KiB
TOML

# maximize lookahead buffer, we don't actually gc so we only get one pass
# of the disk for these tests
defines.LOOKAHEAD_SIZE = 'BLOCK_COUNT / 8'
[cases.b2_btree_lookup]
defines.N = [8, 16, 32, 64, 128, 256, 1024]
# 0 = in-order
# 1 = reversed-order
# 2 = random-order
defines.ORDER = [0, 1, 2]
defines.SEED = 42
in = 'lfs.c'
code = '''
lfs_t lfs;
lfs_init(&lfs, cfg) => 0;
// create free lookahead
memset(lfs.lookahead.buffer, 0, lfs.cfg->lookahead_size);
lfs.lookahead.start = 0;
lfs.lookahead.size = lfs_min(8*lfs.cfg->lookahead_size,
lfs.cfg->block_count);
lfs.lookahead.next = 0;
lfs_alloc_ack(&lfs);
uint32_t prng = SEED;
// create a tree with N elements
lfsr_btree_t btree = LFSR_BTREE_NULL;
const char *alphas = "abcdefghijklmnopqrstuvwxyz";
for (lfs_size_t i = 0; i < N; i++) {
lfs_off_t i_
= (ORDER == 0) ? i
: (ORDER == 1) ? 0
: BENCH_PRNG(&prng) % (lfsr_btree_weight(&btree)+1);
lfsr_btree_push(&lfs, &btree, i_, LFSR_TAG_INLINED, 1,
LFSR_DATA_BUF(&alphas[i % 26], 1)) => 0;
}
// assume an unfetched btree
btree.root.off = 0;
// bench lookup
BENCH_START();
lfs_size_t i = BENCH_PRNG(&prng) % N;
uint8_t buffer[4];
lfsr_tag_t tag_;
lfs_size_t weight_;
lfsr_btree_get(&lfs, &btree, i,
&tag_, &weight_, buffer, 4) => 1;
assert(tag_ == LFSR_TAG_INLINED);
assert(weight_ == 1);
BENCH_STOP();
'''
[cases.b2_btree_commit]
defines.N = [8, 16, 32, 64, 128, 256, 1024]
# 0 = in-order
# 1 = reversed-order
# 2 = random-order
defines.ORDER = [0, 1, 2]
defines.SEED = 42
defines.AMORTIZED = false
in = 'lfs.c'
code = '''
lfs_t lfs;
lfs_init(&lfs, cfg) => 0;
// create free lookahead
memset(lfs.lookahead.buffer, 0, lfs.cfg->lookahead_size);
lfs.lookahead.start = 0;
lfs.lookahead.size = lfs_min(8*lfs.cfg->lookahead_size,
lfs.cfg->block_count);
lfs.lookahead.next = 0;
lfs_alloc_ack(&lfs);
uint32_t prng = SEED;
// create a tree with N elements
if (AMORTIZED) {
BENCH_START();
}
lfsr_btree_t btree = LFSR_BTREE_NULL;
const char *alphas = "abcdefghijklmnopqrstuvwxyz";
for (lfs_size_t i = 0; i < N; i++) {
lfs_off_t i_
= (ORDER == 0) ? i
: (ORDER == 1) ? 0
: BENCH_PRNG(&prng) % (lfsr_btree_weight(&btree)+1);
lfsr_btree_push(&lfs, &btree, i_, LFSR_TAG_INLINED, 1,
LFSR_DATA_BUF(&alphas[i % 26], 1)) => 0;
}
// bench appending a new id
if (!AMORTIZED) {
BENCH_START();
}
lfs_size_t i = BENCH_PRNG(&prng) % N;
lfsr_btree_push(&lfs, &btree, i, LFSR_TAG_INLINED, 1,
LFSR_DATA_BUF(&alphas[i % 26], 1)) => 0;
BENCH_STOP();
uint8_t buffer[4];
lfsr_tag_t tag_;
lfs_size_t weight_;
lfsr_btree_get(&lfs, &btree, i,
&tag_, &weight_, buffer, 4) => 1;
assert(tag_ == LFSR_TAG_INLINED);
assert(weight_ == 1);
'''