read-cache: add simple performance test

Add the helper test-read-cache, which can be used to call read_cache and discard_cache in a loop as well as a performance check based on it. Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 9, 2013 at 19:39 UTC 1ecb5ff141f6e54727c746446b52af51016e662c
4 files changed +29
.gitignore
+1
@@ -190,6 +190,7 @@
190 /test-mktemp
191 /test-parse-options
192 /test-path-utils
193 +/test-read-cache
194 /test-regex
195 /test-revision-walking
196 /test-run-command
Makefile
+1
@@ -558,6 +558,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
558 TEST_PROGRAMS_NEED_X += test-mktemp
559 TEST_PROGRAMS_NEED_X += test-parse-options
560 TEST_PROGRAMS_NEED_X += test-path-utils
561 +TEST_PROGRAMS_NEED_X += test-read-cache
562 TEST_PROGRAMS_NEED_X += test-regex
563 TEST_PROGRAMS_NEED_X += test-revision-walking
564 TEST_PROGRAMS_NEED_X += test-run-command
t/perf/p0002-read-cache.sh new
+14
@@ -0,0 +1,14 @@
1 +#!/bin/sh
2 +
3 +test_description="Tests performance of reading the index"
4 +
5 +. ./perf-lib.sh
6 +
7 +test_perf_default_repo
8 +
9 +count=1000
10 +test_perf "read_cache/discard_cache $count times" "
11 + test-read-cache $count
12 +"
13 +
14 +test_done
test-read-cache.c new
+13
@@ -0,0 +1,13 @@
1 +#include "cache.h"
2 +
3 +int main (int argc, char **argv)
4 +{
5 + int i, cnt = 1;
6 + if (argc == 2)
7 + cnt = strtol(argv[1], NULL, 0);
8 + for (i = 0; i < cnt; i++) {
9 + read_cache();
10 + discard_cache();
11 + }
12 + return 0;
13 +}