zig/lib/std/zig/perf_test.zig
Andrew Kelley d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00

41 lines
1.3 KiB
Zig

const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
const Tokenizer = std.zig.Tokenizer;
const Parser = std.zig.Parser;
const io = std.io;
const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
const source = @embedFile("../os.zig");
var fixed_buffer_mem: [10 * 1024 * 1024]u8 = undefined;
pub fn main() !void {
var i: usize = 0;
var timer = try std.time.Timer.start();
const start = timer.lap();
const iterations = 100;
var memory_used: usize = 0;
while (i < iterations) : (i += 1) {
memory_used += testOnce();
}
const end = timer.read();
memory_used /= iterations;
const elapsed_s = @intToFloat(f64, end - start) / std.time.ns_per_s;
const bytes_per_sec_float = @intToFloat(f64, source.len * iterations) / elapsed_s;
const bytes_per_sec = @floatToInt(u64, @floor(bytes_per_sec_float));
var stdout_file = std.io.getStdOut();
const stdout = stdout_file.writer();
try stdout.print("parsing speed: {:.2}/s, {:.2} used \n", .{
fmtIntSizeBin(bytes_per_sec),
fmtIntSizeBin(memory_used),
});
}
fn testOnce() usize {
var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
var allocator = &fixed_buf_alloc.allocator;
_ = std.zig.parse(allocator, source) catch @panic("parse failure");
return fixed_buf_alloc.end_index;
}