diff options
| author | 2024-02-18 23:19:16 -0400 | |
|---|---|---|
| committer | 2024-02-18 23:19:16 -0400 | |
| commit | bf66906dcf8817d1b4341fd7a5fdbefe972e1cbb (patch) | |
| tree | a78b30c2f380cda174cf1dcf9d15342c2e445ce0 /src | |
| parent | center, padLeft, padRight, and wrap (diff) | |
| download | zg-bf66906dcf8817d1b4341fd7a5fdbefe972e1cbb.tar.gz zg-bf66906dcf8817d1b4341fd7a5fdbefe972e1cbb.tar.xz zg-bf66906dcf8817d1b4341fd7a5fdbefe972e1cbb.zip | |
Tried SIMD lower/upper string. Slower than linear.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index 7ff07ee..7acb9ac 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -5,8 +5,10 @@ const std = @import("std"); | |||
| 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 | // const ascii = @import("ascii"); | ||
| 11 | const ascii = std.ascii; | ||
| 10 | 12 | ||
| 11 | pub fn main() !void { | 13 | pub fn main() !void { |
| 12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 14 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -18,18 +20,19 @@ pub fn main() !void { | |||
| 18 | 20 | ||
| 19 | // var iter = GraphemeIterator.init(input); | 21 | // var iter = GraphemeIterator.init(input); |
| 20 | // var iter = CodePointIterator{ .bytes = input }; | 22 | // var iter = CodePointIterator{ .bytes = input }; |
| 21 | var iter = std.mem.splitScalar(u8, input, '\n'); | 23 | // var iter = std.mem.splitScalar(u8, input, '\n'); |
| 22 | 24 | ||
| 25 | var buf: [1024 * 1024 * 5]u8 = undefined; | ||
| 23 | var result: usize = 0; | 26 | var result: usize = 0; |
| 24 | // var result: isize = 0; | 27 | // var result: isize = 0; |
| 25 | var timer = try std.time.Timer.start(); | 28 | var timer = try std.time.Timer.start(); |
| 26 | 29 | ||
| 27 | // for (0..50) |_| { | ||
| 28 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 30 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 29 | // while (iter.next()) |_| result += 1; | 31 | // while (iter.next()) |_| result += 1; |
| 30 | while (iter.next()) |line| result += strWidth(line); | 32 | // while (iter.next()) |line| result += strWidth(line); |
| 31 | // iter.cp_iter.i = 0; | 33 | const out = ascii.upperString(&buf, input); |
| 32 | // } | 34 | result += out.len; |
| 33 | 35 | ||
| 34 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); | 36 | // std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); |
| 37 | std.debug.print("result: {}, took: {}, s: {s}\n", .{ result, timer.lap(), out[0..16] }); | ||
| 35 | } | 38 | } |