CDC and yaml_bench makefile now always compile with debug

symbols. yaml_bench can now repeat the benchmark many times in a
single run. yaml_gen can now disable collection keys in mappings.
This commit is contained in:
Ferdinand Majerech 2011-10-23 16:10:27 +02:00
parent 13ea5f0c24
commit 915428c8ed
5 changed files with 26 additions and 15 deletions

4
cdc.d
View file

@ -138,7 +138,7 @@ void main(string[] args)
scope(failure){help(); core.stdc.stdlib.exit(-1);} scope(failure){help(); core.stdc.stdlib.exit(-1);}
string[] extra_args = ["-w", "-wi"]; string[] extra_args = ["-gc", "-w", "-wi"];
args = args[1 .. $]; args = args[1 .. $];
foreach(arg; args) foreach(arg; args)
@ -154,7 +154,7 @@ void main(string[] args)
} }
if(args.length > 0 && args[$ - 1][0] != '-'){target = args[$ - 1];} if(args.length > 0 && args[$ - 1][0] != '-'){target = args[$ - 1];}
string[] dbg = ["-gc", "-debug"]; string[] dbg = ["-debug"];
string[] optimize = ["-O", "-inline", "-release"]; string[] optimize = ["-O", "-inline", "-release"];
string[] lib_src = ["dyaml/", "yaml.d"]; string[] lib_src = ["dyaml/", "yaml.d"];

View file

@ -1,5 +1,5 @@
main: main:
dmd -w -I../../ -L-L../../ -L-ldyaml yaml_bench.d dmd -w -gc -I../../ -L-L../../ -L-ldyaml yaml_bench.d
clean: clean:
rm yaml_bench yaml_bench.o rm yaml_bench yaml_bench.o

View file

@ -1,8 +1,10 @@
//Benchmark that loads, and optionally extracts data from and/or emits a YAML file. //Benchmark that loads, and optionally extracts data from and/or emits a YAML file.
import std.conv;
import std.datetime; import std.datetime;
import std.stdio; import std.stdio;
import std.string;
import yaml; import yaml;
///Print help information. ///Print help information.
@ -18,7 +20,8 @@ void help()
"Available options:\n" "Available options:\n"
" -h --help Show this help information.\n" " -h --help Show this help information.\n"
" -g --get Extract data from the file (using Node.get()).\n" " -g --get Extract data from the file (using Node.get()).\n"
" -d --dump Dump the loaded data (to YAML_FILE.dump).\n"; " -d --dump Dump the loaded data (to YAML_FILE.dump).\n"
" -r --runs=NUM Repeat the benchmark NUM times.\n";
writeln(help); writeln(help);
} }
@ -56,16 +59,19 @@ void main(string[] args)
{ {
bool get = false; bool get = false;
bool dump = false; bool dump = false;
uint runs = 1;
string file = null; string file = null;
//Parse command line args //Parse command line args
foreach(arg; args[1 .. $]) foreach(arg; args[1 .. $])
{ {
if(arg[0] == '-') switch(arg) auto parts = arg.split("=");
if(arg[0] == '-') switch(parts[0])
{ {
case "--help", "-h": help(); return; case "--help", "-h": help(); return;
case "--get", "-g": get = true; break; case "--get", "-g": get = true; break;
case "--dump", "-d": dump = true; break; case "--dump", "-d": dump = true; break;
case "--runs", "-r": runs = to!uint(parts[1]); break;
default: writeln("\nUnknown argument: ", arg, "\n\n"); help(); return; default: writeln("\nUnknown argument: ", arg, "\n\n"); help(); return;
} }
else else
@ -89,14 +95,17 @@ void main(string[] args)
try try
{ {
auto nodes = Loader(file).loadAll(); while(runs--)
if(dump)
{ {
Dumper(file ~ ".dump").dump(nodes); auto nodes = Loader(file).loadAll();
} if(dump)
if(get) foreach(ref node; nodes) {
{ Dumper(file ~ ".dump").dump(nodes);
extract(node); }
if(get) foreach(ref node; nodes)
{
extract(node);
}
} }
} }
catch(YAMLException e) catch(YAMLException e)

View file

@ -1,8 +1,9 @@
root-type: seq root-type: seq
documents: 2 documents: 2
complex-keys: false complex-keys: false
min-nodes-per-document: 512 collection-keys: false
encoding: utf-32 min-nodes-per-document: 65536
encoding: utf-8
indent: 4 indent: 4
text-width: 40 text-width: 40

View file

@ -155,7 +155,8 @@ Node genBinary(bool root = false)
Node nodes(in bool root, Node range, in string tag, in bool set = false) Node nodes(in bool root, Node range, in string tag, in bool set = false)
{ {
auto types = typesCollection ~ (set ? typesScalarKey : typesScalar); auto types = config["collection-keys"].as!bool ? typesCollection : [];
types ~= (set ? typesScalarKey : typesScalar);
Node[] nodes; Node[] nodes;
if(root) if(root)