shithub: mc

Download patch

ref: cf1c6aa5e3025d81896eba7d3f0858b37bdc7309
parent: 99cc92c31eadabe470d781af2f5fd4410594e10e
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Sep 3 20:08:07 EDT 2017

Improve sampling of benchmark.

--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -21,8 +21,6 @@
 	const softfail	: (ctx : ctx#, msg : byte[:], args : ... -> void)
 ;;
 
-const Nsamp = 1000;
-
 const bench = {specs
 	std.put("MTEST {}\n", specs.len)
 	for s : specs
@@ -78,7 +76,7 @@
 }
 
 const benchspec = {ts
-	var avg, m, d, n
+	var avg, m, d, n, nsamp
 	var start, dt
 	var ctx : ctx
 	var jmpbuf
@@ -90,9 +88,21 @@
 	avg = 0.0;
 	m = 0.0;
 	n = 0.0;
+	nsamp = 0
 	std.put("test {} <<{{!\n", ts.name)
 	if !std.setjmp(&jmpbuf)
-		for var i = 0; i < Nsamp; i++
+		/* estimate samples */
+		start = std.now()
+		ts.fn(&ctx)
+		dt = (std.now() - start : flt64)
+
+		if dt == 0.0
+			nsamp = 1000_000
+		else
+			nsamp = (1000_000.0/dt : std.time)
+		;;
+
+		for var i = 0; i < nsamp; i++
 			n +=1.0;
 			start = std.now()
 			ts.fn(&ctx)
@@ -104,7 +114,7 @@
 	;;
 
 	if ctx.ok
-		std.put("!}}>> timing {} {} {}\n", Nsamp, avg, m)
+		std.put("!}}>> timing {} {} {}\n", nsamp, avg, m)
 	else
 		std.put("!}}>> fail {}\n", ctx.reason)
 		std.slfree(ctx.reason)
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -89,7 +89,7 @@
 
 	i = 0
 	a = [0, 0, 0]
-	for e in std.bysplit(v, ".")
+	for e : std.bysplit(v, ".")
 		match std.intparse(e)
 		| `std.Some n:	a[i++] = n
 		| `std.None:	continue
--- a/support/dumpleak.myr
+++ b/support/dumpleak.myr
@@ -78,7 +78,7 @@
 	ptr = get64(path, f)
 	sz = get64(path, f)
 	stk = [][:]
-	for var i = 0; i < 10; i++
+	for var i = 0; i < 20; i++
 		std.slpush(&stk, get64(path, f))
 	;;
 	stats.allocs++