Skip to content

Commit 3921a0b

Browse files
Kevin Willfordgitster
authored andcommitted
perf: add test for writing the index
A performance test for writing the index to be able to determine if changes to allocating ondisk structure help. Signed-off-by: Kevin Willford <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b3622a4 commit 3921a0b

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ TEST_PROGRAMS_NEED_X += test-parse-options
655655
TEST_PROGRAMS_NEED_X += test-path-utils
656656
TEST_PROGRAMS_NEED_X += test-prio-queue
657657
TEST_PROGRAMS_NEED_X += test-read-cache
658+
TEST_PROGRAMS_NEED_X += test-write-cache
658659
TEST_PROGRAMS_NEED_X += test-ref-store
659660
TEST_PROGRAMS_NEED_X += test-regex
660661
TEST_PROGRAMS_NEED_X += test-revision-walking

t/helper/test-write-cache.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "cache.h"
2+
#include "lockfile.h"
3+
4+
static struct lock_file index_lock;
5+
6+
int cmd_main(int argc, const char **argv)
7+
{
8+
int i, cnt = 1, lockfd;
9+
if (argc == 2)
10+
cnt = strtol(argv[1], NULL, 0);
11+
setup_git_directory();
12+
read_cache();
13+
for (i = 0; i < cnt; i++) {
14+
lockfd = hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
15+
if (0 <= lockfd) {
16+
write_locked_index(&the_index, &index_lock, COMMIT_LOCK);
17+
} else {
18+
rollback_lock_file(&index_lock);
19+
}
20+
}
21+
22+
return 0;
23+
}

t/perf/p0007-write-cache.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
test_description="Tests performance of writing the index"
4+
5+
. ./perf-lib.sh
6+
7+
test_perf_default_repo
8+
9+
test_expect_success "setup repo" '
10+
if git rev-parse --verify refs/heads/p0006-ballast^{commit}
11+
then
12+
echo Assuming synthetic repo from many-files.sh
13+
git config --local core.sparsecheckout 1
14+
cat >.git/info/sparse-checkout <<-EOF
15+
/*
16+
!ballast/*
17+
EOF
18+
else
19+
echo Assuming non-synthetic repo...
20+
fi &&
21+
nr_files=$(git ls-files | wc -l)
22+
'
23+
24+
count=3
25+
test_perf "write_locked_index $count times ($nr_files files)" "
26+
test-write-cache $count
27+
"
28+
29+
test_done

0 commit comments

Comments
 (0)