diff options
| author | 2024-02-19 09:11:56 -0400 | |
|---|---|---|
| committer | 2024-02-19 09:11:56 -0400 | |
| commit | 6013b2ded106521ee9cae6bd77dacbd5254ff763 (patch) | |
| tree | 990f13cfbe4bfc20a08d2f097c4646984bffb565 /src | |
| parent | Tried SIMD lower/upper string. Slower than linear. (diff) | |
| download | zg-6013b2ded106521ee9cae6bd77dacbd5254ff763.tar.gz zg-6013b2ded106521ee9cae6bd77dacbd5254ff763.tar.xz zg-6013b2ded106521ee9cae6bd77dacbd5254ff763.zip | |
Cleaned up directory structure
Diffstat (limited to 'src')
| -rw-r--r-- | src/grapheme.zig | 2 | ||||
| -rw-r--r-- | src/main.zig | 16 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/grapheme.zig b/src/grapheme.zig index f013aba..3fdf10b 100644 --- a/src/grapheme.zig +++ b/src/grapheme.zig | |||
| @@ -235,7 +235,7 @@ pub fn graphemeBreak( | |||
| 235 | 235 | ||
| 236 | test "Segmentation GraphemeIterator" { | 236 | test "Segmentation GraphemeIterator" { |
| 237 | const allocator = std.testing.allocator; | 237 | const allocator = std.testing.allocator; |
| 238 | var file = try std.fs.cwd().openFile("GraphemeBreakTest.txt", .{}); | 238 | var file = try std.fs.cwd().openFile("data/unicode/auxiliary/GraphemeBreakTest.txt", .{}); |
| 239 | defer file.close(); | 239 | defer file.close(); |
| 240 | var buf_reader = std.io.bufferedReader(file.reader()); | 240 | var buf_reader = std.io.bufferedReader(file.reader()); |
| 241 | var input_stream = buf_reader.reader(); | 241 | var input_stream = buf_reader.reader(); |
diff --git a/src/main.zig b/src/main.zig index 7acb9ac..019076a 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -5,34 +5,30 @@ 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"); | 10 | // const ascii = @import("ascii"); |
| 11 | const ascii = std.ascii; | 11 | // const ascii = std.ascii; |
| 12 | 12 | ||
| 13 | pub fn main() !void { | 13 | pub fn main() !void { |
| 14 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 14 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 15 | defer _ = gpa.deinit(); | 15 | defer _ = gpa.deinit(); |
| 16 | const allocator = gpa.allocator(); | 16 | const allocator = gpa.allocator(); |
| 17 | 17 | ||
| 18 | const input = try std.fs.cwd().readFileAlloc(allocator, "lang_mix.txt", std.math.maxInt(u32)); | 18 | const input = try std.fs.cwd().readFileAlloc(allocator, "data/lang_mix.txt", std.math.maxInt(u32)); |
| 19 | defer allocator.free(input); | 19 | defer allocator.free(input); |
| 20 | 20 | ||
| 21 | // var iter = GraphemeIterator.init(input); | 21 | // var iter = GraphemeIterator.init(input); |
| 22 | // var iter = CodePointIterator{ .bytes = input }; | 22 | // var iter = CodePointIterator{ .bytes = input }; |
| 23 | // var iter = std.mem.splitScalar(u8, input, '\n'); | 23 | var iter = std.mem.splitScalar(u8, input, '\n'); |
| 24 | 24 | ||
| 25 | var buf: [1024 * 1024 * 5]u8 = undefined; | ||
| 26 | var result: usize = 0; | 25 | var result: usize = 0; |
| 27 | // var result: isize = 0; | 26 | // var result: isize = 0; |
| 28 | var timer = try std.time.Timer.start(); | 27 | var timer = try std.time.Timer.start(); |
| 29 | 28 | ||
| 30 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 29 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 31 | // while (iter.next()) |_| result += 1; | 30 | // while (iter.next()) |_| result += 1; |
| 32 | // while (iter.next()) |line| result += strWidth(line); | 31 | while (iter.next()) |line| result += strWidth(line); |
| 33 | const out = ascii.upperString(&buf, input); | ||
| 34 | result += out.len; | ||
| 35 | 32 | ||
| 36 | // std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); | 33 | 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] }); | ||
| 38 | } | 34 | } |