Skip to content

Commit 4853bf6

Browse files
committed
fix: fixes to gh workflow
1 parent 2ed2610 commit 4853bf6

File tree

1 file changed

+4
-146
lines changed

1 file changed

+4
-146
lines changed

.github/workflows/performance-benchmark.yml

Lines changed: 4 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -36,79 +36,8 @@ jobs:
3636
id: current_benchmark
3737
run: |
3838
echo "Running performance benchmark for current version..."
39-
40-
# Create a simple benchmark script
41-
cat > benchmark_current.zig << 'EOF'
42-
const std = @import("std");
43-
const hash_zig = @import("hash-zig");
44-
45-
pub fn main() !void {
46-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
47-
defer _ = gpa.deinit();
48-
const allocator = gpa.allocator();
49-
50-
std.debug.print("Performance Benchmark - Current Version\n", .{});
51-
std.debug.print("=====================================\n", .{});
52-
53-
// Test different lifetimes
54-
const lifetimes = [_]struct { name: []const u8, lifetime: hash_zig.KeyLifetime }{
55-
.{ .name = "2^10", .lifetime = .lifetime_2_10 },
56-
.{ .name = "2^16", .lifetime = .lifetime_2_16 },
57-
};
58-
59-
for (lifetimes) |config| {
60-
std.debug.print("\nTesting lifetime: {s}\n", .{config.name});
61-
std.debug.print("-------------------\n", .{});
62-
63-
const params = hash_zig.Parameters.init(config.lifetime);
64-
var sig_scheme = try hash_zig.HashSignature.init(allocator, params);
65-
defer sig_scheme.deinit();
66-
67-
const seed: [32]u8 = .{42} ** 32;
68-
69-
// Key generation benchmark
70-
const keygen_start = std.time.nanoTimestamp();
71-
var keypair = try sig_scheme.generateKeyPair(allocator, &seed);
72-
const keygen_end = std.time.nanoTimestamp();
73-
defer keypair.deinit(allocator);
74-
75-
const keygen_duration_ns = keygen_end - keygen_start;
76-
const keygen_duration_sec = @as(f64, @floatFromInt(keygen_duration_ns)) / 1_000_000_000.0;
77-
78-
// Sign benchmark
79-
const message = "Performance test message";
80-
const sign_start = std.time.nanoTimestamp();
81-
var signature = try sig_scheme.sign(allocator, message, keypair.secret_key, 0);
82-
const sign_end = std.time.nanoTimestamp();
83-
defer signature.deinit(allocator);
84-
85-
const sign_duration_ns = sign_end - sign_start;
86-
const sign_duration_sec = @as(f64, @floatFromInt(sign_duration_ns)) / 1_000_000_000.0;
87-
88-
// Verify benchmark
89-
const verify_start = std.time.nanoTimestamp();
90-
const is_valid = try sig_scheme.verify(allocator, message, signature, keypair.public_key);
91-
const verify_end = std.time.nanoTimestamp();
92-
93-
const verify_duration_ns = verify_end - verify_start;
94-
const verify_duration_sec = @as(f64, @floatFromInt(verify_duration_ns)) / 1_000_000_000.0;
95-
96-
std.debug.print("Key Generation: {d:.3}s\n", .{keygen_duration_sec});
97-
std.debug.print("Sign: {d:.3}ms\n", .{sign_duration_sec * 1000});
98-
std.debug.print("Verify: {d:.3}ms\n", .{verify_duration_sec * 1000});
99-
std.debug.print("Valid: {}\n", .{is_valid});
100-
101-
// Output results in a format that can be captured
102-
std.debug.print("BENCHMARK_RESULT: {s}:keygen:{d:.6}\n", .{ config.name, keygen_duration_sec });
103-
std.debug.print("BENCHMARK_RESULT: {s}:sign:{d:.6}\n", .{ config.name, sign_duration_sec });
104-
std.debug.print("BENCHMARK_RESULT: {s}:verify:{d:.6}\n", .{ config.name, verify_duration_sec });
105-
}
106-
}
107-
EOF
108-
109-
# Compile and run benchmark
110-
zig build-exe benchmark_current.zig -OReleaseFast --dep hash-zig -Mhash-zig=src/root.zig
111-
./benchmark_current > current_results.txt 2>&1
39+
zig build benchmark -Doptimize=ReleaseFast
40+
./zig-out/bin/hash-zig-benchmark > current_results.txt 2>&1
11241
11342
# Extract key metrics
11443
KEYGEN_2_10=$(grep "BENCHMARK_RESULT: 2^10:keygen:" current_results.txt | cut -d: -f3)
@@ -161,79 +90,8 @@ jobs:
16190
id: base_benchmark
16291
run: |
16392
echo "Running performance benchmark for base version..."
164-
165-
# Create the same benchmark script
166-
cat > benchmark_base.zig << 'EOF'
167-
const std = @import("std");
168-
const hash_zig = @import("hash-zig");
169-
170-
pub fn main() !void {
171-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
172-
defer _ = gpa.deinit();
173-
const allocator = gpa.allocator();
174-
175-
std.debug.print("Performance Benchmark - Base Version\n", .{});
176-
std.debug.print("==================================\n", .{});
177-
178-
// Test different lifetimes
179-
const lifetimes = [_]struct { name: []const u8, lifetime: hash_zig.KeyLifetime }{
180-
.{ .name = "2^10", .lifetime = .lifetime_2_10 },
181-
.{ .name = "2^16", .lifetime = .lifetime_2_16 },
182-
};
183-
184-
for (lifetimes) |config| {
185-
std.debug.print("\nTesting lifetime: {s}\n", .{config.name});
186-
std.debug.print("-------------------\n", .{});
187-
188-
const params = hash_zig.Parameters.init(config.lifetime);
189-
var sig_scheme = try hash_zig.HashSignature.init(allocator, params);
190-
defer sig_scheme.deinit();
191-
192-
const seed: [32]u8 = .{42} ** 32;
193-
194-
// Key generation benchmark
195-
const keygen_start = std.time.nanoTimestamp();
196-
var keypair = try sig_scheme.generateKeyPair(allocator, &seed);
197-
const keygen_end = std.time.nanoTimestamp();
198-
defer keypair.deinit(allocator);
199-
200-
const keygen_duration_ns = keygen_end - keygen_start;
201-
const keygen_duration_sec = @as(f64, @floatFromInt(keygen_duration_ns)) / 1_000_000_000.0;
202-
203-
// Sign benchmark
204-
const message = "Performance test message";
205-
const sign_start = std.time.nanoTimestamp();
206-
var signature = try sig_scheme.sign(allocator, message, keypair.secret_key, 0);
207-
const sign_end = std.time.nanoTimestamp();
208-
defer signature.deinit(allocator);
209-
210-
const sign_duration_ns = sign_end - sign_start;
211-
const sign_duration_sec = @as(f64, @floatFromInt(sign_duration_ns)) / 1_000_000_000.0;
212-
213-
// Verify benchmark
214-
const verify_start = std.time.nanoTimestamp();
215-
const is_valid = try sig_scheme.verify(allocator, message, signature, keypair.public_key);
216-
const verify_end = std.time.nanoTimestamp();
217-
218-
const verify_duration_ns = verify_end - verify_start;
219-
const verify_duration_sec = @as(f64, @floatFromInt(verify_duration_ns)) / 1_000_000_000.0;
220-
221-
std.debug.print("Key Generation: {d:.3}s\n", .{keygen_duration_sec});
222-
std.debug.print("Sign: {d:.3}ms\n", .{sign_duration_sec * 1000});
223-
std.debug.print("Verify: {d:.3}ms\n", .{verify_duration_sec * 1000});
224-
std.debug.print("Valid: {}\n", .{is_valid});
225-
226-
// Output results in a format that can be captured
227-
std.debug.print("BENCHMARK_RESULT: {s}:keygen:{d:.6}\n", .{ config.name, keygen_duration_sec });
228-
std.debug.print("BENCHMARK_RESULT: {s}:sign:{d:.6}\n", .{ config.name, sign_duration_sec });
229-
std.debug.print("BENCHMARK_RESULT: {s}:verify:{d:.6}\n", .{ config.name, verify_duration_sec });
230-
}
231-
}
232-
EOF
233-
234-
# Compile and run benchmark
235-
zig build-exe benchmark_base.zig -OReleaseFast --dep hash-zig -Mhash-zig=src/root.zig
236-
./benchmark_base > base_results.txt 2>&1
93+
zig build benchmark -Doptimize=ReleaseFast
94+
./zig-out/bin/hash-zig-benchmark > base_results.txt 2>&1
23795
23896
# Extract key metrics
23997
KEYGEN_2_10=$(grep "BENCHMARK_RESULT: 2^10:keygen:" base_results.txt | cut -d: -f3)

0 commit comments

Comments
 (0)