summaryrefslogtreecommitdiff
path: root/bench/src/ziglyph_codepoint.zig
blob: 7fe40287364103a4eb1130d58a35a2d3a95cb5b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const std = @import("std");

const CodePointIterator = @import("ziglyph").CodePointIterator;

pub fn main() !void {
    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();
    const allocator = arena.allocator();

    var args_iter = try std.process.argsWithAllocator(allocator);
    _ = args_iter.skip();
    const in_path = args_iter.next() orelse return error.MissingArg;

    const input = try std.fs.cwd().readFileAlloc(
        allocator,
        in_path,
        std.math.maxInt(u32),
    );
    defer allocator.free(input);

    var iter = CodePointIterator{ .bytes = input };
    var result: usize = 0;
    var timer = try std.time.Timer.start();

    while (iter.next()) |_| result += 1;
    std.debug.print("Ziglyph CodePointIterator: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
}