mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 10:05:05 -07:00
Add the ability to convert tests into benchmarks
This commit is contained in:
parent
fb01eda660
commit
e0f6d836a3
14
build.zig
14
build.zig
@ -10,8 +10,11 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
const src_path = "src/libsodium";
|
||||
const src_dir = try fs.Dir.openIterableDir(fs.cwd(), src_path, .{ .no_follow = true });
|
||||
|
||||
var target = b.standardTargetOptions(.{});
|
||||
var mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const enable_benchmarks = b.option(bool, "enable_benchmarks", "Whether tests should be benchmarks.") orelse false;
|
||||
const benchmarks_iterations = b.option(u32, "iterations", "Number of iterations for benchmarks.") orelse 200;
|
||||
|
||||
const static = b.addStaticLibrary("sodium", null);
|
||||
const shared = b.addSharedLibrary("sodium", null, .unversioned);
|
||||
@ -216,6 +219,13 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ test_path, entry.path });
|
||||
exe.addCSourceFiles(&.{full_path}, &.{});
|
||||
exe.strip = true;
|
||||
|
||||
if (enable_benchmarks) {
|
||||
exe.defineCMacro("BENCHMARKS", "1");
|
||||
var buf: [16]u8 = undefined;
|
||||
exe.defineCMacro("ITERATIONS", std.fmt.bufPrintIntToSlice(&buf, benchmarks_iterations, 10, .lower, .{}));
|
||||
}
|
||||
|
||||
exe.install();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user