From 1f55fccc26840b70459f301882f0e225f9bd36d3 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Mon, 4 Aug 2014 02:14:37 +0200 Subject: [PATCH] Updated yaml_bench to benchmark parsing, not Loader construction. --- examples/yaml_bench/yaml_bench.d | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/yaml_bench/yaml_bench.d b/examples/yaml_bench/yaml_bench.d index 9d4a19a..e22430d 100644 --- a/examples/yaml_bench/yaml_bench.d +++ b/examples/yaml_bench/yaml_bench.d @@ -108,15 +108,30 @@ void main(string[] args) import std.file; void[] fileInMemory; if(!reload) { fileInMemory = std.file.read(file); } + void[] fileWorkingCopy = fileInMemory.dup; + + // Instead of constructing a resolver/constructor with each Loader, + // construct them once to remove noise when profiling. + auto resolver = new Resolver(); + auto constructor = new Constructor(); + while(runs--) { + // Loading the file rewrites the loaded buffer, so if we don't reload from + // disk, we need to use a copy of the originally loaded file. if(reload) { fileInMemory = std.file.read(file); } + else { fileWorkingCopy[] = fileInMemory[]; } + void[] fileToLoad = reload ? fileInMemory : fileWorkingCopy; if(scanOnly) { - Loader(fileInMemory).scanBench(); + auto loader = Loader(fileToLoad); + loader.scanBench(); continue; } - auto nodes = Loader(fileInMemory).loadAll(); + auto loader = Loader(fileToLoad); + loader.resolver = resolver; + loader.constructor = constructor; + auto nodes = loader.loadAll(); if(dump) { Dumper(file ~ ".dump").dump(nodes);