programming language
Revisión | 0d76f7e19ef7c9b6dc693fc4e07770d06d5336c1 (tree) |
---|---|
Tiempo | 2022-04-10 21:08:36 |
Autor | dhrname <dhrname@joes...> |
Commiter | dhrname |
Add the time clock for the Parser::parse method
@@ -30,6 +30,7 @@ | ||
30 | 30 | #include <vector> |
31 | 31 | #include <iterator> |
32 | 32 | #include <unordered_map> |
33 | +#include <chrono> | |
33 | 34 | #include "include/node.hpp" |
34 | 35 | #include "include/FlexLexer.h" |
35 | 36 | #include "llvm/ADT/APFloat.h" |
@@ -2045,7 +2046,6 @@ namespace jstr | ||
2045 | 2046 | * 句ノードの位置座標を割り振っていく*/ |
2046 | 2047 | void setCoordinate(Node* phrlist) |
2047 | 2048 | { |
2048 | - | |
2049 | 2049 | while ( phrlist->isNode() ) |
2050 | 2050 | { |
2051 | 2051 | if ( phrlist->isCaseOf(typeid(Phrase*)) ) |
@@ -2058,7 +2058,12 @@ namespace jstr | ||
2058 | 2058 | for (int32_t i = 0;i<BNF_NONTERMINAL_LENGTH;i++) |
2059 | 2059 | { |
2060 | 2060 | int32_t id = bnf[i][j][k]; |
2061 | - if (id == p->tokenId) | |
2061 | + if (id <= 0) | |
2062 | + { | |
2063 | + /*bnfを疎な配列と見なして最適化*/ | |
2064 | + break; | |
2065 | + } | |
2066 | + else if (id == p->tokenId) | |
2062 | 2067 | { |
2063 | 2068 | p->setCoordinate(i, j, k); |
2064 | 2069 | } |
@@ -2089,6 +2094,9 @@ namespace jstr | ||
2089 | 2094 | * 0ならば、ファイルストリーム読み込みが終了したことを示す*/ |
2090 | 2095 | int ret; |
2091 | 2096 | |
2097 | + using namespace std::chrono; | |
2098 | + auto t = system_clock::now(); | |
2099 | + | |
2092 | 2100 | /*currentPhr 変数 |
2093 | 2101 | * 現在の句ノード*/ |
2094 | 2102 | Phrase* currentPhr = nullptr; |
@@ -2100,6 +2108,8 @@ namespace jstr | ||
2100 | 2108 | while ((ret = lexer->yylex()) != 0) |
2101 | 2109 | { |
2102 | 2110 | Phrase* phr = createPhrase(ret); |
2111 | + /*次の一文を書き換えると、メモリ解放ができなくなる | |
2112 | + * phrlistがガベージコレクションのパンくずリストの役割を果たす*/ | |
2103 | 2113 | phrlist->appendChild(phrlist->makeNode(phr)); |
2104 | 2114 | |
2105 | 2115 | switch (ret) |
@@ -2434,6 +2444,10 @@ namespace jstr | ||
2434 | 2444 | ifs.close(); |
2435 | 2445 | delete lexer; |
2436 | 2446 | lexer = nullptr; |
2447 | + | |
2448 | + auto d = system_clock::now()-t; | |
2449 | + std::cout << "something took " << duration_cast<milliseconds>(d).count() << "ms" << std::endl; | |
2450 | + | |
2437 | 2451 | } |
2438 | 2452 | |
2439 | 2453 |