add showing time taken for each solution

This commit is contained in:
Rokas Puzonas 2023-12-16 14:02:51 +02:00
parent 676dceec14
commit 8f9891cdde

View File

@ -73,6 +73,7 @@ fn run(allocator: Allocator, args: *cli) !u8 {
var input = aoc.Input{ .allocator = allocator, .lines = lines.items };
var start_time = std.time.microTimestamp();
var result: aoc.Result = undefined;
if (args.part == 1) {
result = try day.part1.?(&input);
@ -81,6 +82,7 @@ fn run(allocator: Allocator, args: *cli) !u8 {
} else {
unreachable;
}
const end_time = std.time.microTimestamp();
switch (result) {
.uint => std.debug.print("{}\n", .{result.uint}),
@ -89,6 +91,9 @@ fn run(allocator: Allocator, args: *cli) !u8 {
.text => std.debug.print("{s}\n", .{result.text}),
}
const duration = end_time - start_time;
std.debug.print("Time taken: {}ms ({}us)\n", .{@divTrunc(duration, std.time.us_per_ms), duration});
return 0;
}
@ -136,7 +141,7 @@ fn get_input(allocator: Allocator, args: *cli) !u8 {
return 255;
}
const body = try request.reader().readAllAlloc(allocator, kilobytes(8));
const body = try request.reader().readAllAlloc(allocator, kilobytes(128));
defer allocator.free(body);
var file = try std.fs.cwd().createFile(args.input_file, .{ });