Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig binarytrees: use ArenaAllocator #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions bench/algorithm/binarytrees/1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ const MIN_DEPTH = 4;
const global_allocator = std.heap.c_allocator;

pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(global_allocator);
defer arena.deinit();

var allocator = arena.allocator();

const stdout = std.io.getStdOut().writer();
const n = try get_n();
const max_depth = @max(MIN_DEPTH + 2, n);
{
const stretch_depth = max_depth + 1;
const stretch_tree = Node.make(stretch_depth, global_allocator).?;
const stretch_tree = Node.make(stretch_depth, allocator).?;
defer stretch_tree.deinit();
try stdout.print("stretch tree of depth {d}\t check: {d}\n", .{ stretch_depth, stretch_tree.check() });
}
const long_lived_tree = Node.make(max_depth, global_allocator).?;
const long_lived_tree = Node.make(max_depth, allocator).?;
defer long_lived_tree.deinit();

var depth: usize = MIN_DEPTH;
Expand All @@ -25,7 +30,7 @@ pub fn main() !void {
var sum: usize = 0;
var i: usize = 0;
while (i < iterations) : (i += 1) {
const tree = Node.make(depth, global_allocator).?;
const tree = Node.make(depth, allocator).?;
defer tree.deinit();
sum += tree.check();
}
Expand Down