From 6f912e5a681c4b7d45f5998d47858ed9a6d7077c Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Fri, 30 Aug 2024 15:11:25 +0200 Subject: [PATCH] more tinkering --- perftest/source/app.d | 35 ++++++++++++++++++++++++++++------- source/graphql/lexer.d | 4 ++-- source/graphql/tokenmodule.d | 9 ++++----- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/perftest/source/app.d b/perftest/source/app.d index faa08ef..5f2e989 100644 --- a/perftest/source/app.d +++ b/perftest/source/app.d @@ -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); + } } diff --git a/source/graphql/lexer.d b/source/graphql/lexer.d index dfae502..02f4f43 100644 --- a/source/graphql/lexer.d +++ b/source/graphql/lexer.d @@ -20,8 +20,8 @@ struct Lexer { string input; size_t stringPos; - size_t line; - size_t column; + uint line; + ushort column; Token cur; diff --git a/source/graphql/tokenmodule.d b/source/graphql/tokenmodule.d index 9d2d939..2647dd2 100644 --- a/source/graphql/tokenmodule.d +++ b/source/graphql/tokenmodule.d @@ -50,9 +50,9 @@ enum TokenType { struct Token { @safe: - size_t line; - size_t column; string value; + uint line; + ushort column; TokenType type; @@ -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) { @@ -94,4 +94,3 @@ struct Token { this.value); } } -