Skip to content

Commit

Permalink
move Loader.scanBench into benchmark tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Herringway committed Sep 22, 2023
1 parent f3c3e30 commit a0d7705
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
20 changes: 14 additions & 6 deletions examples/yaml_bench/yaml_bench.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import std.range;
import std.stdio;
import std.string;
import dyaml;
import dyaml.reader;
import dyaml.scanner;

///Get data out of every node.
void extract(ref Node document) @safe
Expand Down Expand Up @@ -115,15 +117,21 @@ void main(string[] args) //@safe
else { fileWorkingCopy[] = fileInMemory[]; }
void[] fileToLoad = reload ? fileInMemory : fileWorkingCopy;

auto loader = Loader.fromBuffer(fileToLoad);
if(scanOnly)
{
loader.scanBench();
return;
auto reader = new Reader(cast(ubyte[])fileToLoad, "benchmark");
auto scanner = Scanner(reader);
while(!scanner.empty)
{
scanner.popFront();
}
}
else
{
auto loader = Loader.fromBuffer(fileToLoad);
loader.resolver = resolver;
nodes = loader.array;
}

loader.resolver = resolver;
nodes = loader.array;
}
void runDumpBenchmark() @safe
{
Expand Down
17 changes: 0 additions & 17 deletions source/dyaml/loader.d
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,6 @@ struct Loader
}
return currentNode;
}

// Scan all tokens, throwing them away. Used for benchmarking.
void scanBench() @safe
{
try
{
while(!scanner_.empty)
{
scanner_.popFront();
}
}
catch(YAMLException e)
{
throw new YAMLException("Unable to scan YAML from stream " ~
name_ ~ " : " ~ e.msg, e.file, e.line);
}
}
}
/// Load single YAML document from a file:
@safe unittest
Expand Down

0 comments on commit a0d7705

Please sign in to comment.