Skip to content

Commit

Permalink
more tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Sep 6, 2024
1 parent f4639ca commit 6f912e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
35 changes: 28 additions & 7 deletions perftest/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,32 @@ import countvisitor;

void main() {
string toParse = readText("schema.docs.graphql");
auto l = Lexer(toParse, QueryParser.no);
//auto l = Lexer(toParse);
auto p = Parser(l);
Document d = p.parseDocument();
auto cv = new CountVisitor();
cv.accept(d);
writeln(cv.countsToString());
foreach(i; 0 .. 50) {
auto l = Lexer(toParse, QueryParser.no);
//auto l = Lexer(toParse);
auto p = Parser(l);
Document d = p.parseDocument();
auto cv = new CountVisitor();
cv.accept(d);
doNotOptimizeAway(cv.countsToString());
}
}

void doNotOptimizeAway(T...)(auto ref T t)
{
foreach (ref it; t)
{
doNotOptimizeAwayImpl(&it);
}
}

private void doNotOptimizeAwayImpl(void* p)
{
import core.thread : getpid;
import std.stdio : writeln;

if (getpid() == 0)
{
writeln(p);
}
}
4 changes: 2 additions & 2 deletions source/graphql/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct Lexer {
string input;
size_t stringPos;

size_t line;
size_t column;
uint line;
ushort column;

Token cur;

Expand Down
9 changes: 4 additions & 5 deletions source/graphql/tokenmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ enum TokenType {

struct Token {
@safe:
size_t line;
size_t column;
string value;
uint line;
ushort column;

TokenType type;

Expand All @@ -62,8 +62,8 @@ struct Token {

this(TokenType type, size_t line, size_t column) {
this.type = type;
this.line = line;
this.column = column;
this.line = cast(uint)line;
this.column = cast(ushort)column;
}

this(TokenType type, string value) {
Expand Down Expand Up @@ -94,4 +94,3 @@ struct Token {
this.value);
}
}

0 comments on commit 6f912e5

Please sign in to comment.