summaryrefslogtreecommitdiff
path: root/bench/copious-allocs.myr
diff options
context:
space:
mode:
Diffstat (limited to 'bench/copious-allocs.myr')
-rw-r--r--bench/copious-allocs.myr73
1 files changed, 48 insertions, 25 deletions
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])
;;
}