summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-04 02:58:44 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-04 02:58:54 -0700
commit7ef09f3db883c42d01e3b1d80f0d2da6ceff9913 (patch)
treeaf370bd4f281a680b9793034f3b5baee1aa43471 /bench
parent40d6f7b5cc0cb9e5de1675a1441ad0dfc0a66bda (diff)
downloadmc-7ef09f3db883c42d01e3b1d80f0d2da6ceff9913.tar.gz
Modernize benchmarks.
Diffstat (limited to 'bench')
-rw-r--r--bench/bigfactorial.myr12
-rw-r--r--bench/bld.sub55
-rw-r--r--bench/copious-allocs.myr73
-rw-r--r--bench/intsort.myr8
-rw-r--r--bench/mandelbrot.myr51
-rw-r--r--bench/many-memcpy.myr46
-rw-r--r--bench/regex-match.myr36
-rw-r--r--bench/runbench.myr59
-rw-r--r--bench/sha1-compute.myr30
9 files changed, 173 insertions, 197 deletions
diff --git a/bench/bigfactorial.myr b/bench/bigfactorial.myr
index 4363774..cbaab6c 100644
--- a/bench/bigfactorial.myr
+++ b/bench/bigfactorial.myr
@@ -1,11 +1,13 @@
use std
+use testr
-const N = 600
const main = {
- var i
- for i = 0; i < N; i++
- std.bigfree(bigfact(i))
- ;;
+ testr.bench([
+ [.name="bigfactorial-1", .fn={ctx; bigfact(1)}],
+ [.name="bigfactorial-100", .fn={ctx; bigfact(100)}],
+ [.name="bigfactorial-1000", .fn={ctx; bigfact(1000)}],
+ [.name="bigfactorial-10000", .fn={ctx; bigfact(10000)}],
+ ][:])
}
const bigfact = {n
diff --git a/bench/bld.sub b/bench/bld.sub
index 560ebdf..910de59 100644
--- a/bench/bld.sub
+++ b/bench/bld.sub
@@ -1,57 +1,30 @@
-bin intsort {noinst,tag=bench} =
- intsort.myr
+testdeps =
lib ../lib/std:std
lib ../lib/sys:sys
+ lib ../lib/crypto:crypto
+ lib ../lib/bio:bio
+ lib ../lib/testr:testr
;;
-bin copious-allocs {noinst,tag=bench} =
+
+bench intsort =
+ intsort.myr
+;;
+bench copious-allocs =
copious-allocs.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
;;
-bin sha1-compute {noinst,tag=bench} =
+bench sha1-compute =
sha1-compute.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
- lib ../lib/crypto:crypto
;;
-bin bigfactorial {noinst,tag=bench} =
+bench bigfactorial =
bigfactorial.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
;;
-bin mandelbrot {noinst,tag=bench} =
+bench mandelbrot =
mandelbrot.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
- lib ../lib/bio:bio
;;
-bin regex-match {noinst,tag=bench} =
+bench regex-match =
regex-match.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
- lib ../lib/regex:regex
;;
-bin many-memcpy {noinst,tag=bench} =
+bench many-memcpy =
many-memcpy.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
-;;
-
-# benchmark runner
-bin runbench {noinst,tag=bench} =
- runbench.myr
- lib ../lib/std:std
- lib ../lib/sys:sys
-;;
-
-cmd benchit {tag=bench} =
- ./runbench
- intsort
- copious-allocs
- sha1-compute
- bigfactorial
- mandelbrot
- regex-match
- many-memcpy
;;
diff --git a/bench/copious-allocs.myr b/bench/copious-allocs.myr
index 7b02594..ca450a7 100644
--- a/bench/copious-allocs.myr
+++ b/bench/copious-allocs.myr
@@ -1,37 +1,60 @@
use std
+use testr
type blob = struct
x : int[10]
;;
const main = {
+ testr.bench([
+ [.name="alloc-one", .fn=alloc_one],
+ [.name="allocmany-fwdfwd", .fn=alloc_fwdfwd],
+ [.name="allocmany-fwdrev", .fn=alloc_fwdrev],
+ [.name="allocmany-fwdrand", .fn=alloc_fwdrand],
+ ][:])
+}
+
+const alloc_one = {ctx
+ var a : int#
+ a = std.alloc()
+ std.free(a)
+}
+
+const alloc_fwdfwd = {ctx
+ var a : blob#[10000]
+
+ /* alloc forwards, dealloc forwards */
+ for var i = 0; i < a.len; i++
+ a[i] = std.alloc()
+ ;;
+ for var i = 0; i < a.len; i++
+ std.free(a[i])
+ ;;
+
+}
+
+const alloc_fwdrev = {ctx
var a : blob#[10000]
- for var j = 0; j < 100; j++
- /* alloc forwards, dealloc forwards */
- for var i = 0; i < a.len; i++
- a[i] = std.alloc()
- ;;
- for var i = 0; i < a.len; i++
- std.free(a[i])
- ;;
-
- /* alloc forwards, dealloc backwards */
- for var i = 0; i < a.len; i++
- a[i] = std.alloc()
- ;;
- for var i = a.len; i > 0; i--
- std.free(a[i - 1])
- ;;
-
- /* alloc forwards, dealloc randomly */
- for var i = 0; i < a.len; i++
- a[i] = std.alloc()
- ;;
- shuffle(a[:])
- for var i = a.len; i > 0; i--
- std.free(a[i - 1])
- ;;
+ /* alloc forwards, dealloc backwards */
+ for var i = 0; i < a.len; i++
+ a[i] = std.alloc()
+ ;;
+ for var i = a.len; i > 0; i--
+ std.free(a[i - 1])
+ ;;
+}
+
+const alloc_fwdrand = {ctx
+ var a : blob#[10000]
+
+ /* alloc forwards, dealloc randomly */
+ for var i = 0; i < a.len; i++
+ a[i] = std.alloc()
+ ;;
+ shuffle(a[:])
+ for var i = a.len; i > 0; i--
+ std.free(a[i - 1])
;;
}
diff --git a/bench/intsort.myr b/bench/intsort.myr
index cb7478c..ff69d3e 100644
--- a/bench/intsort.myr
+++ b/bench/intsort.myr
@@ -1,6 +1,13 @@
use std
+use testr
const main = {
+ testr.bench([
+ [.name="fill-sort", .fn={ctx; benchsort()}]
+ ][:])
+}
+
+const benchsort = {
var a, i
a = std.slalloc(500_000)
@@ -8,4 +15,5 @@ const main = {
a[i] = std.randnum()
;;
std.sort(a, std.numcmp)
+ std.slfree(a)
}
diff --git a/bench/mandelbrot.myr b/bench/mandelbrot.myr
index cf75fda..1d3ad01 100644
--- a/bench/mandelbrot.myr
+++ b/bench/mandelbrot.myr
@@ -1,9 +1,39 @@
use std
use bio
+use testr
const Bailout : flt64 = 16.0
const Maxiter = 1000
+const main = {
+ testr.bench([
+ [.name="mandelbrot", .fn=writemandel]
+ ][:])
+}
+
+
+const writemandel = {ctx
+ 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")
+ /* we still use this fd to log our test output... */
+ bio.flush(f)
+}
+
const mandelbrot = {x, y
var cr, ci, zr, zi
var tmp, zr2, zi2
@@ -32,24 +62,3 @@ const mandelbrot = {x, y
;;
-> 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/many-memcpy.myr b/bench/many-memcpy.myr
index 94a5486..7fce209 100644
--- a/bench/many-memcpy.myr
+++ b/bench/many-memcpy.myr
@@ -1,27 +1,31 @@
use std
+use testr
+
+var a : uint64[100000]
const main = {
- var a : uint64[100000]
-
- for var j = 0; j < 100; j++
- /* independent copies forward */
- for var i = 0; i < 10; i++
- std.slcp(a[:a.len/2-1], a[a.len/2+1:])
- ;;
- /* independent copies backward */
- for var i = 0; i < 10; i++
- std.slcp(a[:a.len/2-1], a[a.len/2+1:])
- ;;
-
- /* dependent copies forward */
- for var i = 0; i < 10; i++
- std.slcp(a[:a.len/2+1000], a[a.len/2-1000:])
- ;;
- /* dependent copies backward */
- for var i = 0; i < 10; i++
- std.slcp(a[a.len/2-1000:], a[:a.len/2+1000])
- ;;
- ;;
+ testr.bench([
+ [.name="fwd-independent", .fn=fwd_independent],
+ [.name="rev-independent", .fn=rev_independent],
+ [.name="fwd-dependent", .fn=fwd_dependent],
+ [.name="rev-dependent", .fn=rev_dependent],
+ ][:])
+}
+
+const fwd_independent = {ctx
+ std.slcp(a[:a.len/2-1], a[a.len/2+1:])
+}
+
+const rev_independent = {ctx
+ std.slcp(a[:a.len/2-1], a[a.len/2+1:])
+}
+
+const fwd_dependent = {ctx
+ std.slcp(a[:a.len/2+1000], a[a.len/2-1000:])
+}
+
+const rev_dependent = {ctx
+ std.slcp(a[a.len/2-1000:], a[:a.len/2+1000])
}
diff --git a/bench/regex-match.myr b/bench/regex-match.myr
index 47c9264..dd78860 100644
--- a/bench/regex-match.myr
+++ b/bench/regex-match.myr
@@ -1,26 +1,36 @@
use std
use regex
+use testr
-const main = {
- var str, re, i
+var str
+var dotstar, hello
- str = "€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝüüü€i²æ&±-ŝüüü€i²æ&±-ŝü"
+const main = {
+ str = std.sldup("hello world!")
str = std.strcat(str, str)
str = std.strcat(str, str)
str = std.strcat(str, str)
str = std.strcat(str, str)
- for i = 0; i < 100; i++
- match regex.compile(".*")
- | `std.Ok r: re = r
- | `std.Err m: std.fatal("couldn't compile regex: %s\n", m)
- ;;
+ dotstar = std.try(regex.compile(".*"))
+ hello = std.try(regex.compile("hel*o"))
+
+ testr.bench([
+ [.name="matchall", .fn=matchall],
+ [.name="searchhello", .fn=searchhello],
+ ][:])
+}
- match regex.exec(re, str)
- | `std.Some m:
- | `std.None: std.fatal("Didn't match regex\n")
- ;;
+const matchall = {ctx
+ match regex.exec(dotstar, str)
+ | `std.Some m: regex.matchfree(m)
+ | `std.None: std.fatal("Didn't match regex\n")
+ ;;
+}
- regex.free(re)
+const searchhello = {ctx
+ match regex.search(dotstar, str)
+ | `std.Some m: regex.matchfree(m)
+ | `std.None: std.fatal("Didn't match regex\n")
;;
}
diff --git a/bench/runbench.myr b/bench/runbench.myr
deleted file mode 100644
index ea69f83..0000000
--- a/bench/runbench.myr
+++ /dev/null
@@ -1,59 +0,0 @@
-use std
-
-const Nsamp = 10
-
-const main = {args : byte[:][:]
- var tot : flt64
-
- std.put("Running benchmarks: {} samples per binary\n", Nsamp);
- tot = 0.0;
- for arg : args[1:]
- tot = tot + timeit(arg)
- ;;
- std.put("total:\t{}s\n", tot);
-}
-
-const timeit = {prog -> flt64
- var avg, m, d, x, n : flt64
-
- avg = 0.0;
- m = 0.0;
- n = 0.0;
- for var i = 0; i < Nsamp; i++
- n = n + 1.0;
- x = run(prog);
- d = (x - avg);
- avg = avg + d/n;
- m = m + d*(x - avg);
- ;;
- std.put("{}:\t{}s (σ^2: {})\n", prog, avg, m/(n-1.0));
- -> avg;
-}
-
-const run = {prog -> flt64
- var infd, outfd
- var pid
- var tm
-
- tm = std.now()
- pid = std.fork();
- if pid < 0
- std.fatal("Could not fork\n");
- elif pid == 0
- infd = std.try(std.open("/dev/zero", std.Ordonly))
- outfd = std.try(std.open("/dev/null", std.Owronly))
- std.try(std.dup2(infd, 0))
- std.try(std.dup2(outfd, 1))
- std.execv(prog, [prog][:])
- std.fatal("Failed to exec\n")
- else
- match std.wait(pid)
- | `std.Wfailure: std.fatal("could not wait\n")
- | `std.Waiterror: std.fatal("running benchmark failed\n")
- | `std.Wsignalled: std.fatal("running benchmark failed\n")
- | `std.Wsuccess: /* nothing */
- ;;
- ;;
- -> (std.now() - tm : flt64) / 1_000_000.0
-}
-
diff --git a/bench/sha1-compute.myr b/bench/sha1-compute.myr
index e96aa65..def82a0 100644
--- a/bench/sha1-compute.myr
+++ b/bench/sha1-compute.myr
@@ -1,20 +1,26 @@
use crypto
use std
+use testr
+
+var buf : byte[128*1024*1024]
-const N = 20
const main = {
- var i, b
- var buf : byte[1024*1024]
+ for var i = 0; i < buf.len; i++
+ buf[i] = (i : byte)
+ ;;
+ testr.bench([
+ [.name="sha1-1kb", .fn={ctx; hash(std.KiB)}],
+ [.name="sha1-1mb", .fn={ctx; hash(std.MiB)}],
+ [.name="sha1-16mb", .fn={ctx; hash(16*std.MiB)}],
+ [.name="sha1-128mb", .fn={ctx; hash(128*std.MiB)}],
+ ][:])
+}
+
+const hash = {len
var st
- b = 0
- for i = 0; i < buf.len; i++
- buf[i] = b++
- ;;
- for i = 0; i < N; i++
- crypto.sha1init(&st)
- crypto.sha1add(&st, buf[:])
- crypto.sha1fin(&st)
- ;;
+ crypto.sha1init(&st)
+ crypto.sha1add(&st, buf[:len])
+ crypto.sha1fin(&st)
}