authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-07-09 17:14:04+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-07-09 17:14:04+12:00
log82e9190d0939a7f71df3d602e381b0ec7cccb561
tree2dade6482d90748065a89f5391a3716c1c1a3ecd
parent410b4d9bdf8abb8dad2ac2e11038fe492b8be869

Update zig.parser benchmark program


1 files changed, 6 insertions(+), 8 deletions(-)

std/zig/bench.zig+6-8
...@@ -19,20 +19,18 @@ pub fn main() !void {...@@ -19,20 +19,18 @@ pub fn main() !void {
19 }19 }
20 const end = timer.read();20 const end = timer.read();
21 memory_used /= iterations;21 memory_used /= iterations;
22 const elapsed_s = f64(end - start) / std.os.time.ns_per_s;22 const elapsed_s = @intToFloat(f64, end - start) / std.os.time.ns_per_s;
23 const bytes_per_sec = f64(source.len * iterations) / elapsed_s;23 const bytes_per_sec = @intToFloat(f64, source.len * iterations) / elapsed_s;
24 const mb_per_sec = bytes_per_sec / (1024 * 1024);24 const mb_per_sec = bytes_per_sec / (1024 * 1024);
2525
26 var stdout_file = try std.io.getStdOut();26 var stdout_file = try std.io.getStdOut();
27 const stdout = *std.io.FileOutStream.init(*stdout_file).stream;27 const stdout = &std.io.FileOutStream.init(&stdout_file).stream;
28 try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);28 try stdout.print("{.3} MiB/s, {} KiB used \n", mb_per_sec, memory_used / 1024);
29}29}
3030
31fn testOnce() usize {31fn testOnce() usize {
32 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);32 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
33 var allocator = *fixed_buf_alloc.allocator;33 var allocator = &fixed_buf_alloc.allocator;
34 var tokenizer = Tokenizer.init(source);34 _ = std.zig.parse(allocator, source) catch @panic("parse failure");
35 var parser = Parser.init(*tokenizer, allocator, "(memory buffer)");
36 _ = parser.parse() catch @panic("parse failure");
37 return fixed_buf_alloc.end_index;35 return fixed_buf_alloc.end_index;
38}36}