Skip to content

Commit f00a039

Browse files
rscharfegitster
authored andcommitted
test-mergesort: use DEFINE_LIST_SORT_DEBUG
Define a typed sort function using DEFINE_LIST_SORT_DEBUG for the mergesort sanity check instead of using llist_mergesort(). This gets rid of the next pointer accessor functions and improves the performance at the cost of slightly bigger object text. Before: Benchmark 1: t/helper/test-tool mergesort test Time (mean ± σ): 108.4 ms ± 0.2 ms [User: 106.7 ms, System: 1.2 ms] Range (min … max): 108.0 ms … 108.8 ms 27 runs __TEXT __DATA __OBJC others dec hex 6251 276 0 23172 29699 7403 t/helper/test-mergesort.o With this patch: Benchmark 1: t/helper/test-tool mergesort test Time (mean ± σ): 94.0 ms ± 0.2 ms [User: 92.4 ms, System: 1.1 ms] Range (min … max): 93.7 ms … 94.5 ms 31 runs __TEXT __DATA __OBJC others dec hex 6407 276 0 24701 31384 7a98 t/helper/test-mergesort.o Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 318051e commit f00a039

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

t/helper/test-mergesort.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,11 @@ struct number {
273273
struct number *next;
274274
};
275275

276-
static void *get_next_number(const void *a)
277-
{
278-
stats.get_next++;
279-
return ((const struct number *)a)->next;
280-
}
281-
282-
static void set_next_number(void *a, void *b)
283-
{
284-
stats.set_next++;
285-
((struct number *)a)->next = b;
286-
}
276+
DEFINE_LIST_SORT_DEBUG(static, sort_numbers, struct number, next,
277+
stats.get_next++, stats.set_next++);
287278

288-
static int compare_numbers(const void *av, const void *bv)
279+
static int compare_numbers(const struct number *an, const struct number *bn)
289280
{
290-
const struct number *an = av, *bn = bv;
291281
int a = an->value, b = bn->value;
292282
stats.compare++;
293283
return (a > b) - (a < b);
@@ -325,8 +315,7 @@ static int test(const struct dist *dist, const struct mode *mode, int n, int m)
325315
*tail = NULL;
326316

327317
stats.get_next = stats.set_next = stats.compare = 0;
328-
list = llist_mergesort(list, get_next_number, set_next_number,
329-
compare_numbers);
318+
sort_numbers(&list, compare_numbers);
330319

331320
QSORT(arr, n, compare_ints);
332321
for (i = 0, curr = list; i < n && curr; i++, curr = curr->next) {

t/t0071-sort.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test_description='verify sort functions'
55
TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77

8-
test_expect_success 'llist_mergesort()' '
8+
test_expect_success 'DEFINE_LIST_SORT_DEBUG' '
99
test-tool mergesort test
1010
'
1111

0 commit comments

Comments
 (0)