summaryrefslogtreecommitdiffstats
path: root/src/bench.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bench.c')
-rw-r--r--src/bench.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/bench.c b/src/bench.c
new file mode 100644
index 0000000..b406be3
--- /dev/null
+++ b/src/bench.c
@@ -0,0 +1,57 @@
+#include "stl.h"
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char buf[BUFSIZ];
+
+static char *stl_err[] = {
+ STL_STRERROR_INIT
+};
+
+int
+main(int argc, const char **argv)
+{
+ struct stl_result res;
+ struct stl stl;
+ size_t count;
+ int n, rc;
+
+ stl_init(&stl, STL_TYPE_DETECT);
+
+ count = 0;
+ while (1) {
+ n = fread(buf, 1, BUFSIZ, stdin);
+ if (n <= 0) errx(1, "truncated input");
+
+ while (1) {
+ rc = stl_feed(&stl, &res, buf, n);
+ if (rc == STL_DONE) break;
+ if (rc == STL_INCOMPLETE) break;
+ if (rc != STL_OK) errx(1, "libstl: %s", stl_err[rc]);
+
+ switch (res.type) {
+ case STL_RES_FILETYPE:
+ printf("filetype: %s\n",
+ res.filetype == STL_TYPE_ASCII
+ ? "ascii" : "binary");
+ break;
+ case STL_RES_HEADER:
+ printf("header: %s\n", res.header.str);
+ break;
+ case STL_RES_SOLID_NAME:
+ printf("name: %s\n", res.solid_name.str);
+ break;
+ case STL_RES_TRIANGLE:
+ count += 1;
+ break;
+ }
+ }
+
+ if (rc == STL_DONE)
+ break;
+ }
+
+ printf("triangles: %lu\n", count);
+}