diff options
author | 2022-03-06 07:35:16 -0800 | |
---|---|---|
committer | 2022-03-06 07:35:16 -0800 | |
commit | 7c5c6cd5192acde43006070e740bbe51cfd49255 (patch) | |
tree | 53f1e3cb999a477791dd76f4f2bedd3c56084756 /src/bench/string-handling.zig | |
parent | 093807391a9563ad36c2b04a286da23d09fad835 (diff) | |
download | bun-7c5c6cd5192acde43006070e740bbe51cfd49255.tar.gz bun-7c5c6cd5192acde43006070e740bbe51cfd49255.tar.zst bun-7c5c6cd5192acde43006070e740bbe51cfd49255.zip |
source maps work for app code in `bun dev`!
Diffstat (limited to 'src/bench/string-handling.zig')
-rw-r--r-- | src/bench/string-handling.zig | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/bench/string-handling.zig b/src/bench/string-handling.zig new file mode 100644 index 000000000..b24af19b9 --- /dev/null +++ b/src/bench/string-handling.zig @@ -0,0 +1,71 @@ +const strings = @import("strings"); +const std = @import("std"); + +pub fn main() anyerror!void { + const args = try std.process.argsAlloc(std.heap.c_allocator); + const filepath = args[args.len - 3]; + const find = args[args.len - 2]; + const amount = try std.fmt.parseInt(usize, args[args.len - 1], 10); + var file = try std.fs.cwd().openFile(filepath, .{ .mode = .read_only }); + var contents = try file.readToEndAlloc(std.heap.c_allocator, std.math.maxInt(usize)); + + { + var timer = try std.time.Timer.start(); + var index: usize = std.math.maxInt(usize); + var j: usize = 0; + var i: usize = 0; + while (j < amount) : (j += 1) { + i = 0; + if (strings.indexOf(contents, find)) |k| { + i += k; + index = k; + } + } + + if (index == std.math.maxInt(usize)) { + std.debug.print("<vec 32> [{d} byte file] {s} NOT found in {}\n", .{ contents.len, find, std.fmt.fmtDuration(timer.read()) }); + } else { + std.debug.print("<vec 32> [{d} byte file] {s} found at {d} in {}\n", .{ contents.len, find, index, std.fmt.fmtDuration(timer.read()) }); + } + } + + { + var timer = try std.time.Timer.start(); + var index: usize = std.math.maxInt(usize); + var j: usize = 0; + var i: usize = 0; + while (j < amount) : (j += 1) { + i = 0; + if (strings.indexOf16(contents, find)) |k| { + i += k; + index = k; + } + } + + if (index == std.math.maxInt(usize)) { + std.debug.print("<vec 16> [{d} byte file] {s} NOT found in {}\n", .{ contents.len, find, std.fmt.fmtDuration(timer.read()) }); + } else { + std.debug.print("<vec 16> [{d} byte file] {s} found at {d} in {}\n", .{ contents.len, find, index, std.fmt.fmtDuration(timer.read()) }); + } + } + + { + var timer = try std.time.Timer.start(); + var index: usize = std.math.maxInt(usize); + var j: usize = 0; + var i: usize = 0; + while (j < amount) : (j += 1) { + i = 0; + if (std.mem.indexOf(u8, contents, find)) |k| { + i += k; + index = k; + } + } + + if (index == std.math.maxInt(usize)) { + std.debug.print("<std> [{d} byte file] {s} NOT found in {}\n", .{ contents.len, find, std.fmt.fmtDuration(timer.read()) }); + } else { + std.debug.print("<std> [{d} byte file] {s} found at {d} in {}\n", .{ contents.len, find, index, std.fmt.fmtDuration(timer.read()) }); + } + } +} |