From bf66906dcf8817d1b4341fd7a5fdbefe972e1cbb Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Sun, 18 Feb 2024 23:19:16 -0400 Subject: Tried SIMD lower/upper string. Slower than linear. --- src/main.zig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') 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"); // const codePointWidth = @import("ziglyph").display_width.codePointWidth; // const codePointWidth = @import("display_width").codePointWidth; // const strWidth = @import("ziglyph").display_width.strWidth; -const strWidth = @import("display_width").strWidth; +// const strWidth = @import("display_width").strWidth; // const CodePointIterator = @import("CodePoint").CodePointIterator; +// const ascii = @import("ascii"); +const ascii = std.ascii; pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; @@ -18,18 +20,19 @@ pub fn main() !void { // var iter = GraphemeIterator.init(input); // var iter = CodePointIterator{ .bytes = input }; - var iter = std.mem.splitScalar(u8, input, '\n'); + // var iter = std.mem.splitScalar(u8, input, '\n'); + var buf: [1024 * 1024 * 5]u8 = undefined; var result: usize = 0; // var result: isize = 0; var timer = try std.time.Timer.start(); - // for (0..50) |_| { // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); // while (iter.next()) |_| result += 1; - while (iter.next()) |line| result += strWidth(line); - // iter.cp_iter.i = 0; - // } + // while (iter.next()) |line| result += strWidth(line); + const out = ascii.upperString(&buf, input); + result += out.len; - std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); + // std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); + std.debug.print("result: {}, took: {}, s: {s}\n", .{ result, timer.lap(), out[0..16] }); } -- cgit v1.2.3