summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-08-15 15:13:44 -0400
committerOri Bernstein <ori@eigenstate.org>2014-08-15 15:13:44 -0400
commit437f6d851e88446fba90495a3175f02e8d3d390c (patch)
tree3bcb1e2b9c9e48e7547570b374c110faef8712d5 /bench
parenta5a4e162cec3bb59c7d88a703d45edc916392453 (diff)
downloadmc-437f6d851e88446fba90495a3175f02e8d3d390c.tar.gz
Add benchmarking runner and makefile.
Now you can do 'make bench', and see how fast Myrddin runs. Or at least the integer sorting bit. TODO: expand this so that you can see how it compares to previous results, and add benchmarks.
Diffstat (limited to 'bench')
-rw-r--r--bench/Makefile13
-rw-r--r--bench/intsort.myr6
-rw-r--r--bench/runner.c69
-rw-r--r--bench/runner.myr23
4 files changed, 106 insertions, 5 deletions
diff --git a/bench/Makefile b/bench/Makefile
new file mode 100644
index 0000000..c94452b
--- /dev/null
+++ b/bench/Makefile
@@ -0,0 +1,13 @@
+BIN=runner
+OBJ=runner.o
+BENCHSRC=intsort.myr
+BENCHUTIL=
+
+include ../config.mk
+include ../mk/c.mk
+
+bench: runner $(BENCHSRC:.myr=)
+ ./runner $(BENCHSRC:.myr=)
+
+$(BENCHSRC:.myr=): $(BENCHSRC) $(BENCHUTIL)
+ ../myrbuild/myrbuild -b $@ $@.myr $(BENCHUTIL)
diff --git a/bench/intsort.myr b/bench/intsort.myr
index d8c3227..008e6ba 100644
--- a/bench/intsort.myr
+++ b/bench/intsort.myr
@@ -4,15 +4,11 @@ const main = {
var a
var i
var rng
- var t0, t1
rng = std.mksrng(123)
- a = std.slalloc(1000000)
+ a = std.slalloc(100_000)
for i = 0; i < a.len; i++
a[i] = std.rand32(rng)
;;
- t0 = std.now()
std.sort(a, std.numcmp)
- t1 = std.now()
- std.put("time = %l\n", t1 - t0)
}
diff --git a/bench/runner.c b/bench/runner.c
new file mode 100644
index 0000000..94c355d
--- /dev/null
+++ b/bench/runner.c
@@ -0,0 +1,69 @@
+/* written in C instead of Myrddin because I don't have FP in Myrddin yet... */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <unistd.h>
+#include <err.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+#define Nsamp 10
+
+double run(char *prog)
+{
+ struct rusage ru;
+ double sec, usec;
+ char *cmd[2];
+ int pid;
+ int status;
+
+ sec = 0;
+ usec = 0;
+ pid = fork();
+ if (pid < 0) {
+ err(1, "Could not fork\n");
+ } else if (pid == 0) {
+ cmd[0] = prog;
+ cmd[1] = NULL;
+ execv(prog, cmd);
+ err(1, "Failed to exec\n");
+ } else {
+ wait4(pid, &status, 0, &ru);
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ err(1, "Subprogram failed to execute\n");
+ sec = ru.ru_utime.tv_sec;
+ usec = ru.ru_utime.tv_usec / (1000.0 * 1000.0);
+ }
+ return sec + usec;
+}
+
+void timed_run(char *prog)
+{
+ double avg, m, d, x;
+ int i, n;
+
+ avg = 0;
+ m = 0;
+ n = 0;
+ for (i = 0; i < Nsamp; i++) {
+ n++;
+ x = run(prog);
+ d = (x - avg);
+ avg += d/n;
+ m = m + d*(x - avg);
+ }
+ printf("%s:\t%fs (σ^2: %f)\n", prog, avg, m/(n-1));
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ printf("Running benchmarks: %d samples per binary\n", Nsamp);
+ for (i = 1; i < argc; i++)
+ timed_run(argv[i]);
+ return 0;
+}
+
diff --git a/bench/runner.myr b/bench/runner.myr
new file mode 100644
index 0000000..8ddc1de
--- /dev/null
+++ b/bench/runner.myr
@@ -0,0 +1,23 @@
+use std
+
+const Nsamp = 10
+
+const main = {args : byte[:][:]
+ for a in args
+ time(a)
+ ;;
+}
+
+const time = {a
+ var rusage
+ var t
+
+ for i = 0; i < Nsamp; i++
+ if !run(a, &rusage)
+ break
+ ;;
+ ;;
+}
+
+
+