/* Test program for comparing malloc performance to kmregion.
kmregion version 3.5, a region-based memory allocator
Copyright (C) 02021 Kragen Javier Sitaker
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
int
main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Usage: %s 1000\n(for 5 million allocations)\n", argv[0]);
return 1;
}
size_t n = atoi(argv[1]);
for (size_t i = 0; i < n; i++) {
//kmregion *p = km_start(km_libc_disc, NULL);
//if (!p) abort();
struct n { int i; struct n *next; } *list = NULL;
for (size_t j = 0; j < 5000; j++) {
struct n *q = malloc(sizeof(*q)); //km_new(p, sizeof(*q));
if (!q) abort();
q->i = j;
q->next = list;
list = q;
}
if (i == 23) {
size_t total = 0;
struct n *q = list;
while (q) {
total += q->i;
q = q->next;
}
printf("Total: %d\n", (int)total);
}
while (list) {
struct n *q = list->next;
free(list);
list = q;
}
// km_end(p);
}
return 0;
}