Skip to content

Commit 43d6a77

Browse files
committed
zig binarytrees: use ArenaAllocator
1 parent 725cf39 commit 43d6a77

File tree

1 file changed

+8
-3
lines changed
  • bench/algorithm/binarytrees

1 file changed

+8
-3
lines changed

bench/algorithm/binarytrees/1.zig

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ const MIN_DEPTH = 4;
77
const global_allocator = std.heap.c_allocator;
88

99
pub fn main() !void {
10+
var arena = std.heap.ArenaAllocator.init(global_allocator);
11+
defer arena.deinit();
12+
13+
var allocator = arena.allocator();
14+
1015
const stdout = std.io.getStdOut().writer();
1116
const n = try get_n();
1217
const max_depth = @max(MIN_DEPTH + 2, n);
1318
{
1419
const stretch_depth = max_depth + 1;
15-
const stretch_tree = Node.make(stretch_depth, global_allocator).?;
20+
const stretch_tree = Node.make(stretch_depth, allocator).?;
1621
defer stretch_tree.deinit();
1722
try stdout.print("stretch tree of depth {d}\t check: {d}\n", .{ stretch_depth, stretch_tree.check() });
1823
}
19-
const long_lived_tree = Node.make(max_depth, global_allocator).?;
24+
const long_lived_tree = Node.make(max_depth, allocator).?;
2025
defer long_lived_tree.deinit();
2126

2227
var depth: usize = MIN_DEPTH;
@@ -25,7 +30,7 @@ pub fn main() !void {
2530
var sum: usize = 0;
2631
var i: usize = 0;
2732
while (i < iterations) : (i += 1) {
28-
const tree = Node.make(depth, global_allocator).?;
33+
const tree = Node.make(depth, allocator).?;
2934
defer tree.deinit();
3035
sum += tree.check();
3136
}

0 commit comments

Comments
 (0)