summaryrefslogtreecommitdiff
path: root/bench/src/ziglyph_case.zig
blob: c6ef6ec3b0770f46af758e745e2a0a6e94cc78a7 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const std = @import("std");

const ziglyph = @import("ziglyph");

pub fn main() !void {
    var args_iter = std.process.args();
    _ = args_iter.skip();
    const in_path = args_iter.next() orelse return error.MissingArg;

    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();
    const allocator = arena.allocator();

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

    var iter = std.mem.splitScalar(u8, input, '\n');
    var result: usize = 0;
    var timer = try std.time.Timer.start();

    while (iter.next()) |line| {
        const upper = try ziglyph.toUpperStr(allocator, line);
        const lower = try ziglyph.toLowerStr(allocator, line);
        result += upper.len + lower.len;
    }
    std.debug.print("Ziglyph toUpperStr/toLowerStr: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });

    result = 0;
    iter.reset();
    timer.reset();

    while (iter.next()) |line| {
        if (ziglyph.isUpperStr(line)) result += 1;
        if (ziglyph.isLowerStr(line)) result += 2;
    }
    std.debug.print("Ziglyph isUpperStr/isLowerStr: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
}