summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-18 16:38:52 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-18 16:38:52 -0400
commit093dd263b29bd0014d4869d7bca8520cc382952e (patch)
tree5c02858ffadf9a87f21d3fc301f7b12a139bc9a8 /bench
parent36a26aa671237ac768d99d0a30edc35fd10dffd0 (diff)
downloadmc-093dd263b29bd0014d4869d7bca8520cc382952e.tar.gz
Add mandelbrot benchmark.
Diffstat (limited to 'bench')
-rw-r--r--bench/Makefile1
-rw-r--r--bench/mandelbrot.myr54
-rw-r--r--bench/runner.c11
3 files changed, 66 insertions, 0 deletions
diff --git a/bench/Makefile b/bench/Makefile
index e6f7381..6adff70 100644
--- a/bench/Makefile
+++ b/bench/Makefile
@@ -4,6 +4,7 @@ BENCHSRC=intsort.myr \
copious-allocs.myr \
sha1-compute.myr \
bigfactorial.myr \
+ mandelbrot.myr
include ../config.mk
include ../mk/c.mk
diff --git a/bench/mandelbrot.myr b/bench/mandelbrot.myr
new file mode 100644
index 0000000..c97176d
--- /dev/null
+++ b/bench/mandelbrot.myr
@@ -0,0 +1,54 @@
+use std
+use bio
+
+const Bailout : flt64 = 16.0
+const Maxiter = 1000
+
+const mandelbrot = {x, y
+ var cr, ci, zr, zi
+ var tmp, zr2, zi2
+ var i : int
+
+ cr = y - 0.5
+ ci = x
+ zr = 0.0
+ zi = 0.0
+
+ i = 0
+
+ while true
+ i++
+ tmp = zr * zi
+ zr2 = zr * zr
+ zi2 = zi * zi
+ zr = zr2 - zi2 + cr
+ zi = tmp + tmp + ci
+ if zi2 + zr2 > Bailout
+ -> i
+ ;;
+ if i > Maxiter
+ -> 0
+ ;;
+ ;;
+}
+
+const main = {args : byte[:][:]
+ var x : flt64, y : flt64, i
+ var f
+
+ f = bio.mkfile(1, bio.Wr)
+ for i = 0; i < 10; i++
+ for y = -39.0; y < 39.0; y = y + 1.0
+ for x = -39.0; x < 39.0; x = x + 1.0
+ if mandelbrot(x/40.0, y/40.0) == 0
+ bio.write(f, "*")
+ else
+ bio.write(f, " ")
+ ;;
+ ;;
+ bio.write(f, "\n")
+ ;;
+ ;;
+ bio.write(f, "\n")
+ bio.close(f)
+}
diff --git a/bench/runner.c b/bench/runner.c
index 94c355d..baa2149 100644
--- a/bench/runner.c
+++ b/bench/runner.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include <sys/types.h>
@@ -15,6 +16,7 @@ double run(char *prog)
{
struct rusage ru;
double sec, usec;
+ int in, out;
char *cmd[2];
int pid;
int status;
@@ -25,6 +27,15 @@ double run(char *prog)
if (pid < 0) {
err(1, "Could not fork\n");
} else if (pid == 0) {
+ if ((in = open("/dev/zero", O_RDONLY)) < 0)
+ err(1, "could not open /dev/zero");
+ if ((out = open("/dev/null", O_WRONLY)) < 0)
+ err(1, "could not open /dev/null");
+ if (dup2(in, 0) < 0)
+ err(1, "could not reopen stdin");
+ if (dup2(out, 1) < 0)
+ err(1, "could not reopen stdout");
+
cmd[0] = prog;
cmd[1] = NULL;
execv(prog, cmd);