diff --git a/build.zig b/build.zig index b35660b..d1c1378 100644 --- a/build.zig +++ b/build.zig @@ -7,6 +7,9 @@ pub fn build(b: *std.Build) void { const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize }); const clap = clap_dep.module("clap"); + const opts = .{ .target = target, .optimize = optimize }; + const zbench_module = b.dependency("zbench", opts).module("zbench"); + var opt = b.addOptions(); opt.addOption([]const u8, "version", "0.0.2"); const exe = b.addExecutable(.{ @@ -17,6 +20,8 @@ pub fn build(b: *std.Build) void { }); exe.root_module.addImport("build_info", opt.createModule()); exe.root_module.addImport("clap", clap); + exe.root_module.addImport("zbench", zbench_module); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); diff --git a/build.zig.zon b/build.zig.zon index 3ba1ebb..3d34a20 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -8,5 +8,9 @@ .url = "https://github.com/Hejsil/zig-clap/archive/master/latest.tar.gz", .hash = "1220c900c70daf3e715fad6f266ec14b1d0f5e6c2d3f34b32142f60306cb9b5e5f05", }, + .zbench = .{ + .url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz", + .hash = "1220fe24b0832ac690c1999d321ee1a220e738db71bf46c7e3a8947139a384f8d51d", + }, }, } diff --git a/src/main.zig b/src/main.zig index 9a92fda..cdeb5b1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,9 +1,10 @@ const std = @import("std"); const clap = @import("clap"); -const build_info = @import("build_info"); +// const build_info = @import("build_info"); const base64 = std.base64; const debug = std.debug; const io = std.io; +const zbench = @import("zbench"); pub fn main() !void { const params = comptime clap.parseParamsComptime( @@ -115,7 +116,8 @@ fn usage() void { } fn version() void { - std.debug.print("b64 - {s}\n", .{build_info.version}); + // std.debug.print("b64 - {s}\n", .{build_info.version}); + std.debug.print("b64 - {s}\n", .{"0.3.0"}); } fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.ArrayList(u8) { @@ -161,6 +163,20 @@ fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 { return decodedString; } +fn bench_decode(allocator: std.mem.Allocator) void { + const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA=="; + + _ = try decode(allocator, base64String); +} + +test "bench decode" { + var bench = try zbench.Benchmark.init(std.testing.allocator, .{}); + defer bench.deinit(); + + try bench.add("bench decode", bench_decode, .{}); + try bench.run(std.io.getStdout().Writer()); +} + test "base64_decode() returns decoded string" { const test_allocator = std.testing.allocator; const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA=="; diff --git a/src/root.zig b/src/root.zig new file mode 100644 index 0000000..ecfeade --- /dev/null +++ b/src/root.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const testing = std.testing; + +export fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try testing.expect(add(3, 7) == 10); +}