Skip to content

Commit

Permalink
add std gzip into benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Feb 7, 2024
1 parent 780c82c commit a885dcd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions bin/deflate_bench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ pub fn run(output: anytype, opt: Options) !void {
switch (opt.alg) {
.deflate => try stdDeflate(input, output, opt),
.zlib => try stdZlib(input, output, opt),
.gzip => {
print("There is no gzip compressor currently in std lib.\n", .{});
},
.gzip => try stdGzip(input, output, opt),
}
} else {
if (opt.level == 0) {
Expand Down Expand Up @@ -196,6 +194,18 @@ pub fn stdZlib(reader: anytype, writer: anytype, opt: Options) !void {
try cmp.finish();
}

pub fn stdGzip(reader: anytype, writer: anytype, opt: Options) !void {
const c_opt: std.compress.gzip.CompressOptions = if (opt.level == 0)
.{ .level = .huffman_only }
else
.{ .level = @enumFromInt(opt.level) };

var cmp = try std.compress.gzip.compress(allocator, writer, c_opt);
defer cmp.deinit();
try stream(reader, cmp.writer());
try cmp.close();
}

pub fn stdDeflate(reader: anytype, writer: anytype, opt: Options) !void {
const c_opt: std.compress.deflate.CompressorOptions = if (opt.level == 0)
.{ .level = .huffman_only }
Expand Down

0 comments on commit a885dcd

Please sign in to comment.