Compare commits
No commits in common. "zbench" and "main" have entirely different histories.
4 changed files with 3 additions and 47 deletions
|
@ -7,9 +7,6 @@ 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(.{
|
||||
|
@ -20,8 +17,6 @@ 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());
|
||||
|
|
|
@ -8,9 +8,5 @@
|
|||
.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 = "1220b7219ed9b700aaac2a5f84af3c2b3a7c8f714f701511912434525f41735f950b",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
31
src/main.zig
31
src/main.zig
|
@ -1,14 +1,12 @@
|
|||
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(
|
||||
\\-b, --benchmark Benchmark
|
||||
\\-h, --help Display this help and exit.
|
||||
\\-d, --decode Decode base64 to string.
|
||||
\\-e, --encode Encode string to base64.
|
||||
|
@ -34,17 +32,9 @@ pub fn main() !void {
|
|||
|
||||
const stdout = std.io.getStdOut();
|
||||
|
||||
if (res.args.benchmark != 0) {
|
||||
var bench = zbench.Benchmark.init(allocator, .{});
|
||||
defer bench.deinit();
|
||||
|
||||
try bench.add("decode", bench_decode, .{});
|
||||
try bench.run(io.getStdOut().writer());
|
||||
}
|
||||
|
||||
if (res.args.help != 0) {
|
||||
usage();
|
||||
try clap.help(io.getStdErr().writer(), clap.Help, ¶ms, .{});
|
||||
try clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{});
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -125,8 +115,7 @@ fn usage() void {
|
|||
}
|
||||
|
||||
fn version() void {
|
||||
// std.debug.print("b64 - {s}\n", .{build_info.version});
|
||||
std.debug.print("b64 - {s}\n", .{"0.3.0"});
|
||||
std.debug.print("b64 - {s}\n", .{build_info.version});
|
||||
}
|
||||
|
||||
fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.ArrayList(u8) {
|
||||
|
@ -172,20 +161,6 @@ 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==";
|
||||
|
|
10
src/root.zig
10
src/root.zig
|
@ -1,10 +0,0 @@
|
|||
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);
|
||||
}
|
Loading…
Reference in a new issue