summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2019-09-23 11:33:41 +0000
committerrodri <rgl@antares-labs.eu>2019-09-23 11:33:41 +0000
commit8c26b78f66c54804aca8ff4b6d11affedf47c767 (patch)
treec3a46f708dca382ad6deb86be3c0b93ee7feaf2e /main.c
downloadjsonbench-master.tar.gz
jsonbench-master.tar.bz2
jsonbench-master.zip
little linear benchmark.HEADmaster
Diffstat (limited to 'main.c')
-rw-r--r--main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..846c8c9
--- /dev/null
+++ b/main.c
@@ -0,0 +1,47 @@
+#include <u.h>
+#include <libc.h>
+#include <json.h>
+
+enum {
+ MB = 1024*1024
+};
+
+vlong t0, Δt;
+
+void
+usage(void)
+{
+ fprint(2, "usage: %s file\n", argv0);
+ exits("usage");
+}
+
+void
+main(int argc, char *argv[])
+{
+ JSON *j;
+ char buf[8*MB];
+ int fd;
+
+ JSONfmtinstall();
+ ARGBEGIN{
+ default: usage();
+ }ARGEND;
+ if(argc != 1)
+ usage();
+ fd = open(argv[0], OREAD);
+ if(fd < 0)
+ sysfatal("open: %r");
+ if(read(fd, buf, sizeof buf) <= 0)
+ sysfatal("read: %r");
+ t0 = nsec();
+ j = jsonparse(buf);
+ Δt = nsec()-t0;
+ fprint(2, "jsonparse took %lldns\n", Δt);
+ if(j == nil)
+ sysfatal("jsonparse: %r");
+ t0 = nsec();
+ print("%J\n", j);
+ Δt = nsec()-t0;
+ fprint(2, "jsonfmt took %lldns\n", Δt);
+ exits(0);
+}