[plist] Add a test mode to get parse timings

It turns out parsing runs at about 40-55MB/s, but that may be down to
allocations.
This commit is contained in:
Bill Currie 2024-10-19 02:19:01 +09:00
parent d780146be3
commit 164c949796

View file

@ -1,8 +1,11 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "QF/plist.h"
#include "QF/quakeio.h"
#include "QF/sys.h"
static const char *test_strings[] = {
"Guarding the entrance to the Grendal\n"
@ -45,9 +48,34 @@ main (int argc, const char **argv)
int res = 0;
size_t i;
for (i = 0; i < num_string_tests; i ++) {
if (!test_string_io (test_strings[i]))
res = 1;
if (argc > 1) {
int64_t start = Sys_LongTime ();
QFile *file = Qopen (argv[1], "rbz");
size_t len = Qfilesize (file);
char *buf = malloc (len + 1);
char *txt = buf;
if (argc > 2) {
txt += atoi (argv[2]);
}
Qread (file, buf, len);
buf[len] = 0;
int64_t read = Sys_LongTime ();
plitem_t *item = PL_GetPropertyList (txt, nullptr);
printf ("%p %d\n", item, PL_Type (item));
free (buf);
int64_t parse = Sys_LongTime ();
PL_Release (item);
int64_t end = Sys_LongTime ();
printf ("total:%g read:%g parse:%g free:%g\n",
(end - start) / 1000.0,
(read - start) / 1000.0,
(parse - read) / 1000.0,
(end - parse) / 1000.0);
} else {
for (i = 0; i < num_string_tests; i ++) {
if (!test_string_io (test_strings[i]))
res = 1;
}
}
return res;
}