diff options
| author | 2024-02-17 09:50:50 -0400 | |
|---|---|---|
| committer | 2024-02-17 09:50:50 -0400 | |
| commit | 6c1a88471fc6444ee93d6ca0c64d0953a0d857ac (patch) | |
| tree | c9ac886559bd1117b75482ab690364a5e792ad2c /src/main.zig | |
| parent | isAsciiOnly SIMD tweaks (diff) | |
| download | zg-6c1a88471fc6444ee93d6ca0c64d0953a0d857ac.tar.gz zg-6c1a88471fc6444ee93d6ca0c64d0953a0d857ac.tar.xz zg-6c1a88471fc6444ee93d6ca0c64d0953a0d857ac.zip | |
GraphemeIterator ASCII optimization 3x faster
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig index e7c0828..bb188ff 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; | 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; |
| 4 | // const GraphemeIterator = @import("Grapheme").GraphemeIterator; | 4 | const GraphemeIterator = @import("Grapheme").GraphemeIterator; |
| 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; | 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; |
| 6 | // const codePointWidth = @import("display_width").codePointWidth; | 6 | // const codePointWidth = @import("display_width").codePointWidth; |
| 7 | // const strWidth = @import("ziglyph").display_width.strWidth; | 7 | // const strWidth = @import("ziglyph").display_width.strWidth; |
| 8 | const strWidth = @import("display_width").strWidth; | 8 | // const strWidth = @import("display_width").strWidth; |
| 9 | const CodePointIterator = @import("CodePoint").CodePointIterator; | 9 | // const CodePointIterator = @import("CodePoint").CodePointIterator; |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -17,15 +17,16 @@ pub fn main() !void { | |||
| 17 | defer allocator.free(input); | 17 | defer allocator.free(input); |
| 18 | 18 | ||
| 19 | var result: usize = 0; | 19 | var result: usize = 0; |
| 20 | // var iter = GraphemeIterator.init(input); | 20 | var iter = GraphemeIterator.init(input); |
| 21 | // var iter = CodePointIterator{ .bytes = input }; | 21 | // var iter = CodePointIterator{ .bytes = input }; |
| 22 | var iter = std.mem.splitScalar(u8, input, '\n'); | 22 | // var iter = std.mem.splitScalar(u8, input, '\n'); |
| 23 | 23 | ||
| 24 | var timer = try std.time.Timer.start(); | 24 | var timer = try std.time.Timer.start(); |
| 25 | 25 | ||
| 26 | // for (0..50) |_| { | 26 | // for (0..50) |_| { |
| 27 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 27 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 28 | while (iter.next()) |line| result += strWidth(line); | 28 | while (iter.next()) |_| result += 1; |
| 29 | // while (iter.next()) |line| result += strWidth(line); | ||
| 29 | // iter.cp_iter.i = 0; | 30 | // iter.cp_iter.i = 0; |
| 30 | // } | 31 | // } |
| 31 | 32 | ||