wip: zBench not ready for 0.13.0

This commit is contained in:
Kalle Carlbark 2024-06-11 22:23:01 +02:00
parent 74536957b0
commit 8484063764
No known key found for this signature in database
4 changed files with 37 additions and 2 deletions

View file

@ -7,6 +7,9 @@ pub fn build(b: *std.Build) void {
const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize }); const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize });
const clap = clap_dep.module("clap"); 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(); var opt = b.addOptions();
opt.addOption([]const u8, "version", "0.0.2"); opt.addOption([]const u8, "version", "0.0.2");
const exe = b.addExecutable(.{ 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("build_info", opt.createModule());
exe.root_module.addImport("clap", clap); exe.root_module.addImport("clap", clap);
exe.root_module.addImport("zbench", zbench_module);
b.installArtifact(exe); b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());

View file

@ -8,5 +8,9 @@
.url = "https://github.com/Hejsil/zig-clap/archive/master/latest.tar.gz", .url = "https://github.com/Hejsil/zig-clap/archive/master/latest.tar.gz",
.hash = "1220c900c70daf3e715fad6f266ec14b1d0f5e6c2d3f34b32142f60306cb9b5e5f05", .hash = "1220c900c70daf3e715fad6f266ec14b1d0f5e6c2d3f34b32142f60306cb9b5e5f05",
}, },
.zbench = .{
.url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz",
.hash = "1220fe24b0832ac690c1999d321ee1a220e738db71bf46c7e3a8947139a384f8d51d",
},
}, },
} }

View file

@ -1,9 +1,10 @@
const std = @import("std"); const std = @import("std");
const clap = @import("clap"); const clap = @import("clap");
const build_info = @import("build_info"); // const build_info = @import("build_info");
const base64 = std.base64; const base64 = std.base64;
const debug = std.debug; const debug = std.debug;
const io = std.io; const io = std.io;
const zbench = @import("zbench");
pub fn main() !void { pub fn main() !void {
const params = comptime clap.parseParamsComptime( const params = comptime clap.parseParamsComptime(
@ -115,7 +116,8 @@ fn usage() void {
} }
fn version() 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) { 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; 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" { test "base64_decode() returns decoded string" {
const test_allocator = std.testing.allocator; const test_allocator = std.testing.allocator;
const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA=="; const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA==";

10
src/root.zig Normal file
View file

@ -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);
}