zig/std/zig/bench.zig
Andrew Kelley fcbb7426fa use * for pointer type instead of &
See #770

To help automatically translate code, see the
zig-fmt-pointer-reform-2 branch.

This will convert all & into *. Due to the syntax
ambiguity (which is why we are making this change),
even address-of & will turn into *, so you'll have
to manually fix thes instances. You will be guaranteed
to get compile errors for them - expected 'type', found 'foo'
2018-05-31 17:28:07 -04:00

39 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 source = @embedFile("../os/index.zig");
var fixed_buffer_mem: [10 * 1024 * 1024]u8 = undefined;
pub fn main() !void {
var i: usize = 0;
var timer = try std.os.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 = f64(end - start) / std.os.time.ns_per_s;
const bytes_per_sec = f64(source.len * iterations) / elapsed_s;
const mb_per_sec = bytes_per_sec / (1024 * 1024);
var stdout_file = try std.io.getStdOut();
const stdout = *std.io.FileOutStream.init(*stdout_file).stream;
try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);
}
fn testOnce() usize {
var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
var allocator = *fixed_buf_alloc.allocator;
var tokenizer = Tokenizer.init(source);
var parser = Parser.init(*tokenizer, allocator, "(memory buffer)");
_ = parser.parse() catch @panic("parse failure");
return fixed_buf_alloc.end_index;
}