also looking at this
Migrate to zig 0.16
#5
13 files
+222
-239
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -1,45 +1,41 @@ | ||
| 1 | 1 | const std = ; |
| 2 | 2 | const Regex = .Regex; |
| 3 | 3 | |
| 4 | pub fn main() !void { | |
| 5 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| 6 | defer _ = gpa.deinit(); | |
| 7 | const allocator = gpa.allocator(); | |
| 8 | ||
| 4 | pub fn main(init: std.process.Init) !void { | |
| 9 | 5 | std.debug.print("=== Simple Regex Benchmarks ===\n\n", .{}); |
| 10 | 6 | |
| 11 | 7 | // Test 1: Literal matching |
| 12 | 8 | { |
| 13 | 9 | std.debug.print("Test 1: Literal matching...\n", .{}); |
| 14 | var regex = try Regex.compile(allocator, "hello"); | |
| 10 | var regex = try Regex.compile(init.gpa, "hello"); | |
| 15 | 11 | defer regex.deinit(); |
| 16 | 12 | |
| 17 | var timer = try std.time.Timer.start(); | |
| 18 | const start = timer.read(); | |
| 19 | ||
| 13 | const start = std.Io.Timestamp.now(init.io, .real); | |
| 20 | 14 | const iterations: usize = 10000; |
| 21 | 15 | var i: usize = 0; |
| 22 | 16 | while (i < iterations) : (i += 1) { |
| 23 | 17 | _ = try regex.isMatch("hello world"); |
| 24 | 18 | } |
| 25 | 19 | |
| 26 | const elapsed = timer.read() - start; | |
| 27 | const avg_ns = elapsed / iterations; | |
| 20 | const end = std.Io.Timestamp.now(init.io, .real); | |
| 21 | const elapsed = start.durationTo(end); | |
| 22 | ||
| 23 | const avg_ns = @divTrunc(elapsed.nanoseconds, iterations); | |
| 24 | ||
| 28 | 25 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 29 | 26 | iterations, |
| 30 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, | |
| 31 | @as(f64, @floatFromInt(avg_ns)) / 1000.0, | |
| 27 | @as(f64, @floatFromInt(elapsed.toMilliseconds())), | |
| 28 | @as(f64, @floatFromInt(avg_ns)) / std.time.us_per_ms, | |
| 32 | 29 | }); |
| 33 | 30 | } |
| 34 | 31 | |
| 35 | 32 | // Test 2: Quantifiers |
| 36 | 33 | { |
| 37 | 34 | std.debug.print("Test 2: Quantifiers (a+)...\n", .{}); |
| 38 | var regex = try Regex.compile(allocator, "a+"); | |
| 35 | var regex = try Regex.compile(init.gpa, "a+"); | |
| 39 | 36 | defer regex.deinit(); |
| 40 | 37 | |
| 41 | var timer = try std.time.Timer.start(); | |
| 42 | const start = timer.read(); | |
| 38 | const start = std.Io.Timestamp.now(init.io, .real); | |
| 43 | 39 | |
| 44 | 40 | const iterations: usize = 10000; |
| 45 | 41 | var i: usize = 0; |
| @@ -47,23 +43,24 @@ pub fn main() !void { | ||
| 47 | 43 | _ = try regex.isMatch("aaaa"); |
| 48 | 44 | } |
| 49 | 45 | |
| 50 | const elapsed = timer.read() - start; | |
| 51 | const avg_ns = elapsed / iterations; | |
| 46 | const end = std.Io.Timestamp.now(init.io, .real); | |
| 47 | const elapsed = start.durationTo(end); | |
| 48 | const avg_ns = @divTrunc(elapsed.nanoseconds, iterations); | |
| 49 | ||
| 52 | 50 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 53 | 51 | iterations, |
| 54 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, | |
| 55 | @as(f64, @floatFromInt(avg_ns)) / 1000.0, | |
| 52 | @as(f64, @floatFromInt(elapsed.toMilliseconds())), | |
| 53 | @as(f64, @floatFromInt(avg_ns)) / std.time.us_per_ms, | |
| 56 | 54 | }); |
| 57 | 55 | } |
| 58 | 56 | |
| 59 | 57 | // Test 3: Character classes |
| 60 | 58 | { |
| 61 | 59 | std.debug.print("Test 3: Digit matching (\\d+)...\n", .{}); |
| 62 | var regex = try Regex.compile(allocator, "\\d+"); | |
| 60 | var regex = try Regex.compile(init.gpa, "\\d+"); | |
| 63 | 61 | defer regex.deinit(); |
| 64 | 62 | |
| 65 | var timer = try std.time.Timer.start(); | |
| 66 | const start = timer.read(); | |
| 63 | const start = std.Io.Timestamp.now(init.io, .real); | |
| 67 | 64 | |
| 68 | 65 | const iterations: usize = 10000; |
| 69 | 66 | var i: usize = 0; |
| @@ -71,23 +68,24 @@ pub fn main() !void { | ||
| 71 | 68 | _ = try regex.isMatch("12345"); |
| 72 | 69 | } |
| 73 | 70 | |
| 74 | const elapsed = timer.read() - start; | |
| 75 | const avg_ns = elapsed / iterations; | |
| 71 | const end = std.Io.Timestamp.now(init.io, .real); | |
| 72 | const elapsed = start.durationTo(end); | |
| 73 | const avg_ns = @divTrunc(elapsed.nanoseconds, iterations); | |
| 74 | ||
| 76 | 75 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 77 | 76 | iterations, |
| 78 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, | |
| 79 | @as(f64, @floatFromInt(avg_ns)) / 1000.0, | |
| 77 | @as(f64, @floatFromInt(elapsed.toMilliseconds())), | |
| 78 | @as(f64, @floatFromInt(avg_ns)) / std.time.us_per_ms, | |
| 80 | 79 | }); |
| 81 | 80 | } |
| 82 | 81 | |
| 83 | 82 | // Test 4: Case-insensitive |
| 84 | 83 | { |
| 85 | 84 | std.debug.print("Test 4: Case-insensitive matching...\n", .{}); |
| 86 | var regex = try Regex.compileWithFlags(allocator, "hello", .{ .case_insensitive = true }); | |
| 85 | var regex = try Regex.compileWithFlags(init.gpa, "hello", .{ .case_insensitive = true }); | |
| 87 | 86 | defer regex.deinit(); |
| 88 | 87 | |
| 89 | var timer = try std.time.Timer.start(); | |
| 90 | const start = timer.read(); | |
| 88 | const start = std.Io.Timestamp.now(init.io, .real); | |
| 91 | 89 | |
| 92 | 90 | const iterations: usize = 10000; |
| 93 | 91 | var i: usize = 0; |
| @@ -95,12 +93,14 @@ pub fn main() !void { | ||
| 95 | 93 | _ = try regex.isMatch("HELLO"); |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | const elapsed = timer.read() - start; | |
| 99 | const avg_ns = elapsed / iterations; | |
| 96 | const end = std.Io.Timestamp.now(init.io, .real); | |
| 97 | const elapsed = start.durationTo(end); | |
| 98 | const avg_ns = @divTrunc(elapsed.nanoseconds, iterations); | |
| 99 | ||
| 100 | 100 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 101 | 101 | iterations, |
| 102 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, | |
| 103 | @as(f64, @floatFromInt(avg_ns)) / 1000.0, | |
| 102 | @as(f64, @floatFromInt(elapsed.toMilliseconds())), | |
| 103 | @as(f64, @floatFromInt(avg_ns)) / std.time.us_per_ms, | |
| 104 | 104 | }); |
| 105 | 105 | } |
| 106 | 106 | |