also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | const std = ; |
| 2 | const Clock = std.Io.Clock; | |
| 2 | 3 | const Regex = .Regex; |
| 3 | 4 | |
| 4 | pub fn main() !void { | |
| 5 | pub fn main(init: std.process.Init) !void { | |
| 5 | 6 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 7 | const io = init.io; | |
| 6 | 8 | defer _ = gpa.deinit(); |
| 7 | 9 | const allocator = gpa.allocator(); |
| 8 | 10 | |
| @@ -11,11 +13,10 @@ pub fn main() !void { | ||
| 11 | 13 | // Test 1: Literal matching |
| 12 | 14 | { |
| 13 | 15 | std.debug.print("Test 1: Literal matching...\n", .{}); |
| 14 | var regex = try Regex.compile(allocator, "hello"); | |
| 16 | var regex = try Regex.compile(allocator, io, "hello"); | |
| 15 | 17 | defer regex.deinit(); |
| 16 | 18 | |
| 17 | var timer = try std.time.Timer.start(); | |
| 18 | const start = timer.read(); | |
| 19 | const start = Clock.awake.now(io); | |
| 19 | 20 | |
| 20 | 21 | const iterations: usize = 10000; |
| 21 | 22 | var i: usize = 0; |
| @@ -23,8 +24,8 @@ pub fn main() !void { | ||
| 23 | 24 | _ = try regex.isMatch("hello world"); |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | const elapsed = timer.read() - start; | |
| 27 | const avg_ns = elapsed / iterations; | |
| 27 | const elapsed = start.untilNow(io, .awake).toNanoseconds(); | |
| 28 | const avg_ns = @divExact(elapsed, iterations); | |
| 28 | 29 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 29 | 30 | iterations, |
| 30 | 31 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, |
| @@ -35,11 +36,10 @@ pub fn main() !void { | ||
| 35 | 36 | // Test 2: Quantifiers |
| 36 | 37 | { |
| 37 | 38 | std.debug.print("Test 2: Quantifiers (a+)...\n", .{}); |
| 38 | var regex = try Regex.compile(allocator, "a+"); | |
| 39 | var regex = try Regex.compile(allocator, init.io, "a+"); | |
| 39 | 40 | defer regex.deinit(); |
| 40 | 41 | |
| 41 | var timer = try std.time.Timer.start(); | |
| 42 | const start = timer.read(); | |
| 42 | const start = Clock.awake.now(init.io); | |
| 43 | 43 | |
| 44 | 44 | const iterations: usize = 10000; |
| 45 | 45 | var i: usize = 0; |
| @@ -47,8 +47,8 @@ pub fn main() !void { | ||
| 47 | 47 | _ = try regex.isMatch("aaaa"); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | const elapsed = timer.read() - start; | |
| 51 | const avg_ns = elapsed / iterations; | |
| 50 | const elapsed = start.untilNow(init.io, .awake).toNanoseconds(); | |
| 51 | const avg_ns = @divExact(elapsed, iterations); | |
| 52 | 52 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 53 | 53 | iterations, |
| 54 | 54 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, |
| @@ -59,11 +59,10 @@ pub fn main() !void { | ||
| 59 | 59 | // Test 3: Character classes |
| 60 | 60 | { |
| 61 | 61 | std.debug.print("Test 3: Digit matching (\\d+)...\n", .{}); |
| 62 | var regex = try Regex.compile(allocator, "\\d+"); | |
| 62 | var regex = try Regex.compile(allocator, init.io, "\\d+"); | |
| 63 | 63 | defer regex.deinit(); |
| 64 | 64 | |
| 65 | var timer = try std.time.Timer.start(); | |
| 66 | const start = timer.read(); | |
| 65 | const start = Clock.awake.now(init.io); | |
| 67 | 66 | |
| 68 | 67 | const iterations: usize = 10000; |
| 69 | 68 | var i: usize = 0; |
| @@ -71,8 +70,8 @@ pub fn main() !void { | ||
| 71 | 70 | _ = try regex.isMatch("12345"); |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | const elapsed = timer.read() - start; | |
| 75 | const avg_ns = elapsed / iterations; | |
| 73 | const elapsed = start.untilNow(init.io, .awake).toNanoseconds(); | |
| 74 | const avg_ns = @divExact(elapsed, iterations); | |
| 76 | 75 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 77 | 76 | iterations, |
| 78 | 77 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, |
| @@ -83,11 +82,10 @@ pub fn main() !void { | ||
| 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(allocator, init.io, "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 = Clock.awake.now(init.io); | |
| 91 | 89 | |
| 92 | 90 | const iterations: usize = 10000; |
| 93 | 91 | var i: usize = 0; |
| @@ -95,8 +93,8 @@ 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 elapsed = start.untilNow(init.io, .awake).toNanoseconds(); | |
| 97 | const avg_ns = @divExact(elapsed, iterations); | |
| 100 | 98 | std.debug.print(" {d} iterations in {d:.2}ms ({d:.2}µs/op)\n\n", .{ |
| 101 | 99 | iterations, |
| 102 | 100 | @as(f64, @floatFromInt(elapsed)) / 1_000_000.0, |