Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bench/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ pub fn build(b: *std.Build) void {
"Only run micro benchmark tests whose names contain this filter",
);
const profile = buildProfileOption(b);
const native_keccak = nativeKeccakOption(b, profile);

const evmz_dep = b.dependency("evmz", .{
.target = target,
.optimize = optimize,
.profile = profile,
.@"native-keccak" = native_keccak,
});
const evmone_dep = b.dependency("evmone", .{ .target = target, .optimize = optimize });
const intx_dep = b.dependency("intx", .{ .target = target, .optimize = optimize });
Expand Down Expand Up @@ -194,6 +196,8 @@ pub fn build(b: *std.Build) void {
@tagName(compare_optimize),
"--profile",
profile,
"--native-keccak",
native_keccak,
"--support-min",
vm_loop_support_min,
"--support-max",
Expand All @@ -211,6 +215,8 @@ pub fn build(b: *std.Build) void {
b.graph.zig_exe,
"--profile",
profile,
"--native-keccak",
native_keccak,
});
run_report.setCwd(b.path("."));
if (b.args) |args| run_report.addArgs(args);
Expand All @@ -222,6 +228,7 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = micro_optimize,
.profile = profile,
.@"native-keccak" = native_keccak,
});
const micro_evmz_mod = micro_evmz_dep.module("evmz");
micro_evmz_mod.omit_frame_pointer = true;
Expand Down Expand Up @@ -299,6 +306,14 @@ fn buildProfileOption(b: *std.Build) []const u8 {
return profile;
}

fn nativeKeccakOption(b: *std.Build, profile: []const u8) []const u8 {
const backend = b.option([]const u8, "native-keccak", "Native Keccak backend: std or xkcp") orelse "std";
if (!std.mem.eql(u8, backend, "std") and !std.mem.eql(u8, backend, "xkcp")) {
std.debug.panic("unsupported native Keccak backend '{s}' (expected std or xkcp)", .{backend});
}
return if (std.mem.eql(u8, profile, "native")) backend else "std";
}

fn addRevmNativeRustFlags(run: *std.Build.Step.Run) void {
run.setEnvironmentVariable("RUSTFLAGS", "-C target-cpu=native -C force-frame-pointers=no");
run.setEnvironmentVariable("CARGO_PROFILE_RELEASE_LTO", "fat");
Expand Down
10 changes: 8 additions & 2 deletions bench/scripts/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--zig-exe", default="zig")
parser.add_argument("--optimize", default="ReleaseFast")
parser.add_argument("--profile", choices=("native", "zkvm"), default="native")
parser.add_argument("--native-keccak", choices=("std", "xkcp"), default="std")
parser.add_argument("--out-dir", default="../output/bench-report")
parser.add_argument("--report")
parser.add_argument("--checkpoint")
Expand All @@ -94,7 +95,10 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--host-iterations", type=int, default=100_000)
parser.add_argument("--repeats", type=int, default=5)
parser.add_argument("--warmups", type=int, default=1)
return parser.parse_args()
args = parser.parse_args()
if args.profile == "zkvm":
args.native_keccak = "std"
return args


def resolve_path(value: str | Path) -> Path:
Expand All @@ -110,6 +114,8 @@ def collect_environment(args: argparse.Namespace) -> dict[str, Any]:
"platform": f"{platform.system()} {platform.machine()}",
"zig": command_version([args.zig_exe, "version"]),
"profile": args.profile,
"native_keccak": args.native_keccak,
"keccak_provider": args.native_keccak if args.profile == "native" else "zkvm",
"rustc": tool_major_version(command_version(["rustc", "--version"])),
"cargo": tool_major_version(command_version(["cargo", "--version"])),
"solc": solc_version(),
Expand Down Expand Up @@ -294,7 +300,7 @@ def vm_loop_scope(engine: str) -> str:


def build_profile_args(args: argparse.Namespace) -> list[str]:
return [f"-Dprofile={args.profile}"]
return [f"-Dprofile={args.profile}", f"-Dnative-keccak={args.native_keccak}"]


def run_host_matrix(args: argparse.Namespace, raw_dir: Path, out_dir: Path) -> list[dict[str, Any]]:
Expand Down
16 changes: 16 additions & 0 deletions bench/src/compare.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Options = struct {
zig_exe: []const u8 = "zig",
optimize: []const u8 = "ReleaseFast",
profile: []const u8 = "native",
native_keccak: []const u8 = "std",
support_min: ?[]const u8 = null,
support_max: ?[]const u8 = null,
engines: std.ArrayList(Engine) = .empty,
Expand Down Expand Up @@ -150,6 +151,11 @@ fn parseOptions(init: std.process.Init, allocator: std.mem.Allocator) !Options {
options.profile = try parseProfile(allocator, value);
} else if (stripPrefix(arg, "--profile=")) |value| {
options.profile = try parseProfile(allocator, value);
} else if (std.mem.eql(u8, arg, "--native-keccak")) {
const value = args.next() orelse return error.MissingNativeKeccak;
options.native_keccak = try parseNativeKeccak(allocator, value);
} else if (stripPrefix(arg, "--native-keccak=")) |value| {
options.native_keccak = try parseNativeKeccak(allocator, value);
} else if (std.mem.eql(u8, arg, "--support-min")) {
const value = args.next() orelse return error.MissingSupportMin;
options.support_min = try allocator.dupe(u8, value);
Expand Down Expand Up @@ -199,6 +205,7 @@ fn parseOptions(init: std.process.Init, allocator: std.mem.Allocator) !Options {
}
}

if (std.mem.eql(u8, options.profile, "zkvm")) options.native_keccak = "std";
return options;
}

Expand All @@ -212,6 +219,7 @@ fn printUsage() void {
\\ --zig-exe <path> Zig executable used for child bench steps
\\ --optimize <mode> Zig/C++ runner optimization mode, default ReleaseFast
\\ --profile <profile> evmz build profile forwarded to child Zig builds
\\ --native-keccak <name> native Keccak backend forwarded to evmz builds
\\ --support-min <name> minimum evmz fork compiled into the VM-loop runner
\\ --support-max <name> maximum evmz fork compiled into the VM-loop runner
\\ --engine <name> engine filter, repeatable; all, evmz, evmone, revm, evmone-baseline, evmone-advanced, revm-interpreter
Expand Down Expand Up @@ -287,6 +295,7 @@ fn engineCommand(
}
if (engine == .evmz) {
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-Dprofile={s}", .{options.profile}));
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-Dnative-keccak={s}", .{options.native_keccak}));
if (options.support_min) |support_min| {
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-Dbench-support-min={s}", .{support_min}));
}
Expand Down Expand Up @@ -690,6 +699,13 @@ fn parseProfile(allocator: std.mem.Allocator, value: []const u8) ![]const u8 {
return allocator.dupe(u8, value);
}

fn parseNativeKeccak(allocator: std.mem.Allocator, value: []const u8) ![]const u8 {
if (!std.mem.eql(u8, value, "std") and !std.mem.eql(u8, value, "xkcp")) {
return error.UnsupportedNativeKeccak;
}
return allocator.dupe(u8, value);
}

test "parse timing rows ignores non-floats" {
const times = try parseTimesMs(std.testing.allocator, "1.0\nnoise\n2.5\n");
defer std.testing.allocator.free(times);
Expand Down
Loading
Loading