From f3536f7aa94bb2a1ae7ea55ffd7dda7886f5eaf3 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 23 Mar 2024 12:16:56 +0000 Subject: [PATCH] Add some additional allocation benchmarks --- test/jitperf.c | 2 +- test/perf/alloc.vhd | 28 ++++++--- test/perf/binarytrees.vhd | 116 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 test/perf/binarytrees.vhd diff --git a/test/jitperf.c b/test/jitperf.c index 6d6f76a0..ef3f27f3 100644 --- a/test/jitperf.c +++ b/test/jitperf.c @@ -191,7 +191,7 @@ int main(int argc, char **argv) mspace_stack_limit(MSPACE_CURRENT_FRAME); intern_strings(); - opt_set_str(OPT_GC_VERBOSE, NULL); + opt_set_str(OPT_GC_VERBOSE, getenv("NVC_GC_VERBOSE")); opt_set_int(OPT_RELAXED, 1); _std_standard_init(); diff --git a/test/perf/alloc.vhd b/test/perf/alloc.vhd index c2288f40..dcd6ff34 100644 --- a/test/perf/alloc.vhd +++ b/test/perf/alloc.vhd @@ -1,5 +1,6 @@ package alloc is - procedure test_rand; + procedure test_rand_small; + procedure test_rand_large; end package; library ieee; @@ -20,10 +21,13 @@ package body alloc is data : bv_ptr; end record; - shared variable global : list_ptr; - shared variable count : natural; + type bv_ptr_array is array (natural range <>) of bv_ptr; + type bv_ptr_array_ptr is access bv_ptr_array; - procedure test_rand is + shared variable global, delete : list_ptr; + shared variable count : natural := 0; + + procedure do_rand_test (max_size : real; max_count : positive) is variable r : real; variable p : list_ptr; variable n : natural; @@ -32,13 +36,13 @@ package body alloc is p := new list; p.chain := global; uniform(seed1, seed2, r); - p.data := new bit_vector(1 to integer(r * 100000.0)); + p.data := new bit_vector(1 to integer(r * max_size)); global := p; count := count + 1; - if count > 100 then - n := integer(r * 99.0); + if count > max_count then + n := integer(r * real(max_count - 1)); p := global; for j in 1 to n loop p := p.chain; @@ -49,4 +53,14 @@ package body alloc is end loop; end procedure; + procedure test_rand_small is + begin + do_rand_test(1000.0, 500); + end procedure; + + procedure test_rand_large is + begin + do_rand_test(100000.0, 100); + end procedure; + end package body; diff --git a/test/perf/binarytrees.vhd b/test/perf/binarytrees.vhd new file mode 100644 index 00000000..9710c2e7 --- /dev/null +++ b/test/perf/binarytrees.vhd @@ -0,0 +1,116 @@ +package binarytrees is + procedure test_binarytrees; +end package; + +package body binarytrees is + type treeNode; + type treeNodePtr is access treeNode; + + type treeNode is record + left, right : treeNodePtr; + end record; + + procedure NewTreeNode (variable left, right : in treeNodePtr; + result : out treeNodePtr) is + begin + result := new TreeNode'(left, right); + end procedure; + + procedure ItemCheck (variable tree : in treeNodePtr; + result : out integer) is + variable left_sum, right_sum : integer; + begin + if tree.left = null then + result := 1; + else + ItemCheck(tree.left, left_sum); + ItemCheck(tree.right, right_sum); + result := 1 + left_sum + right_sum; + end if; + end procedure; + + procedure BottomUpTree (depth : in integer; + result : out treeNodePtr) is + variable left, right : treeNodePtr; + begin + if depth > 0 then + BottomUpTree(depth - 1, left); + BottomUpTree(depth - 1, right); + end if; + NewTreeNode(left, right, result); + end procedure; + + procedure DeleteTree (tree : inout treeNodePtr) is + begin + if tree.left /= null then + DeleteTree(tree.left); + DeleteTree(tree.right); + end if; + + deallocate(tree); + end procedure; + + procedure test_binarytrees is + constant VERBOSE : boolean := false; + constant N : integer := 10; + variable minDepth : integer; + variable maxDepth : integer; + variable stretchDepth : integer; + variable check : integer; + variable depth : integer; + variable iterations : integer; + variable sum : integer; + variable stretchTree : treeNodePtr; + variable longLivedTree : treeNodePtr; + variable tempTree : treeNodePtr; + begin + minDepth := 4; + + if minDepth + 2 > N then + maxDepth := minDepth + 2; + else + maxDepth := N; + end if; + + stretchDepth := maxDepth + 1; + + BottomUpTree(stretchDepth, stretchTree); + ItemCheck(stretchTree, check); + + assert not VERBOSE report "stretch tree of depth " + & integer'image(stretchDepth) + & HT & " check: " & integer'image(check) + severity note; + + DeleteTree(stretchTree); + + BottomUpTree(maxDepth, longLivedTree); + + depth := minDepth; + while depth <= maxDepth loop + iterations := 2 ** (maxDepth - depth + minDepth); + check := 0; + + for i in 1 to iterations loop + BottomUpTree(depth, temptree); + ItemCheck(tempTree, sum); + check := check + sum; + DeleteTree(tempTree); + end loop; + + assert not VERBOSE report integer'image(iterations) & HT + & " trees of depth " & integer'image(depth) + & HT & " check: " & integer'image(check) + severity note; + + depth := depth + 2; + end loop; + + ItemCheck(longLivedTree, check); + assert not VERBOSE report "long lived tree of depth " + & integer'image(maxDepth) + & HT & " check: " & integer'image(check) + severity note; + + end procedure; +end package body; -- 2.39.2