@@ -11,8 +11,8 @@ pub fn main() !void {
1111
1212 const iterations = 50_000 ;
1313 const zlog_ns = benchZlog (iterations );
14- const alloc_print_ns = benchAllocPrint (allocator , iterations );
15- const buf_print_ns = benchBufPrint (iterations );
14+ const alloc_print_ns = try benchAllocPrint (allocator , iterations );
15+ const buf_print_ns = try benchBufPrint (iterations );
1616
1717 printCase ("zlog sync logger" , iterations , zlog_ns );
1818 printCase ("std.fmt.allocPrint" , iterations , alloc_print_ns );
@@ -41,32 +41,32 @@ fn benchZlog(iterations: usize) i128 {
4141 return support .nowNs () - start ;
4242}
4343
44- fn benchAllocPrint (allocator : std.mem.Allocator , iterations : usize ) i128 {
44+ fn benchAllocPrint (allocator : std.mem.Allocator , iterations : usize ) ! i128 {
4545 const start = support .nowNs ();
4646 for (0.. iterations ) | i | {
47- const line = std .fmt .allocPrint (
47+ const line = try std .fmt .allocPrint (
4848 allocator ,
4949 "{{\" level\" :\" Info\" ,\" message\" :\" User action\" ,\" user_id\" :\" 12345\" ,\" action\" :\" login\" ,\" timestamp\" :{d}}}\n " ,
5050 .{i },
51- ) catch unreachable ;
51+ );
5252 allocator .free (line );
5353 }
5454 return support .nowNs () - start ;
5555}
5656
57- fn benchBufPrint (iterations : usize ) i128 {
57+ fn benchBufPrint (iterations : usize ) ! i128 {
5858 var sink_buffer : [256 ]u8 = undefined ;
5959 var sink = std .Io .Writer .Discarding .init (& sink_buffer );
6060 var line_buffer : [160 ]u8 = undefined ;
6161
6262 const start = support .nowNs ();
6363 for (0.. iterations ) | i | {
64- const line = std .fmt .bufPrint (
64+ const line = try std .fmt .bufPrint (
6565 & line_buffer ,
6666 "{{\" level\" :\" Info\" ,\" message\" :\" User action\" ,\" user_id\" :\" 12345\" ,\" action\" :\" login\" ,\" timestamp\" :{d}}}\n " ,
6767 .{i },
68- ) catch unreachable ;
69- sink .writer .writeAll (line ) catch unreachable ;
68+ );
69+ try sink .writer .writeAll (line );
7070 }
7171 return support .nowNs () - start ;
7272}
0 commit comments