Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Java - Styve - Teachers Choice Interpreted Language
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leo
Java - Styve - Teachers Choice Interpreted Language
Commits
98738c94
Commit
98738c94
authored
9 months ago
by
Leo
Browse files
Options
Downloads
Patches
Plain Diff
feat: add performance exec time tracking for the parser
parent
2720b349
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Main.java
+5
-1
5 additions, 1 deletion
src/Main.java
src/frontend/Performance.java
+17
-0
17 additions, 0 deletions
src/frontend/Performance.java
src/frontend/parser/Parser.java
+27
-16
27 additions, 16 deletions
src/frontend/parser/Parser.java
with
49 additions
and
17 deletions
src/Main.java
+
5
−
1
View file @
98738c94
import
frontend.Performance
;
import
frontend.ast.ASTPrettyPrinter
;
import
frontend.ast.ASTPrettyPrinter
;
import
frontend.ast.ProgramStmt
;
import
frontend.ast.ProgramStmt
;
import
frontend.lexer.CodeReconstructor
;
import
frontend.lexer.CodeReconstructor
;
...
@@ -108,7 +109,10 @@ public class Main {
...
@@ -108,7 +109,10 @@ public class Main {
}
}
System
.
out
.
println
(
Colors
.
BLUE
+
"Output:"
);
System
.
out
.
println
(
Colors
.
BLUE
+
"Output:"
);
System
.
out
.
println
(
"="
.
repeat
(
25
)
+
"\n"
+
Colors
.
RESET
);
System
.
out
.
println
(
"="
.
repeat
(
25
)
+
"\n"
+
Colors
.
RESET
);
Interpreter
.
evaluate
(
program
,
rootEnv
,
debug
);
boolean
finalDebug
=
debug
;
Performance
.
timeFunction
(()
->
{
Interpreter
.
evaluate
(
program
,
rootEnv
,
finalDebug
);
},
"Executing program"
);
}
catch
(
Parser
.
ParserException
e
)
{
}
catch
(
Parser
.
ParserException
e
)
{
System
.
out
.
println
(
"Parser error: "
+
e
.
getMessage
());
System
.
out
.
println
(
"Parser error: "
+
e
.
getMessage
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
This diff is collapsed.
Click to expand it.
src/frontend/Performance.java
0 → 100644
+
17
−
0
View file @
98738c94
package
frontend
;
public
class
Performance
{
public
static
void
timeFunction
(
Runnable
function
)
{
long
startTime
=
System
.
nanoTime
();
function
.
run
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
(
endTime
-
startTime
)
/
1000000
;
System
.
out
.
println
(
Constants
.
Colors
.
YELLOW
+
"Execution time: "
+
duration
+
"ms"
+
Constants
.
Colors
.
RESET
);
}
public
static
void
timeFunction
(
Runnable
function
,
String
message
)
{
System
.
out
.
println
(
Constants
.
Colors
.
YELLOW
+
message
+
Constants
.
Colors
.
RESET
);
timeFunction
(
function
);
}
}
This diff is collapsed.
Click to expand it.
src/frontend/parser/Parser.java
+
27
−
16
View file @
98738c94
package
frontend.parser
;
package
frontend.parser
;
import
frontend.Constants
;
import
frontend.Constants
;
import
frontend.Performance
;
import
frontend.ast.*
;
import
frontend.ast.*
;
import
frontend.ast.object.ObjectLiteral
;
import
frontend.ast.object.ObjectLiteral
;
import
frontend.ast.object.PropertyLiteral
;
import
frontend.ast.object.PropertyLiteral
;
...
@@ -67,7 +68,10 @@ public class Parser {
...
@@ -67,7 +68,10 @@ public class Parser {
*/
*/
public
ProgramStmt
parse
(
String
sourceCode
)
throws
ParserException
{
public
ProgramStmt
parse
(
String
sourceCode
)
throws
ParserException
{
Lexer
lexer
=
new
Lexer
();
Lexer
lexer
=
new
Lexer
();
Performance
.
timeFunction
(()
->
{
this
.
tokens
=
lexer
.
tokenize
(
sourceCode
);
this
.
tokens
=
lexer
.
tokenize
(
sourceCode
);
System
.
out
.
println
(
Constants
.
Colors
.
YELLOW
+
"Source code tokens: "
+
this
.
tokens
.
size
()
+
Constants
.
Colors
.
RESET
);
},
"Lexing source code..."
);
this
.
reset
();
this
.
reset
();
if
(
this
.
debug
)
{
if
(
this
.
debug
)
{
for
(
Token
token
:
this
.
tokens
)
{
for
(
Token
token
:
this
.
tokens
)
{
...
@@ -75,6 +79,7 @@ public class Parser {
...
@@ -75,6 +79,7 @@ public class Parser {
}
}
}
}
List
<
Stmt
>
programBody
=
new
ArrayList
<>();
List
<
Stmt
>
programBody
=
new
ArrayList
<>();
Performance
.
timeFunction
(()
->
{
this
.
print
(
"Parsing program body, is not EOF: "
+
this
.
notEOF
());
this
.
print
(
"Parsing program body, is not EOF: "
+
this
.
notEOF
());
while
(
this
.
notEOF
())
{
while
(
this
.
notEOF
())
{
this
.
print
(
"Pre-parse statement: "
+
this
.
peek
());
this
.
print
(
"Pre-parse statement: "
+
this
.
peek
());
...
@@ -89,9 +94,15 @@ public class Parser {
...
@@ -89,9 +94,15 @@ public class Parser {
ProgramStmt
program
=
new
ProgramStmt
(
1
,
programBody
);
ProgramStmt
program
=
new
ProgramStmt
(
1
,
programBody
);
System
.
out
.
println
(
ASTPrettyPrinter
.
toRepr
(
program
,
0
,
2
));
System
.
out
.
println
(
ASTPrettyPrinter
.
toRepr
(
program
,
0
,
2
));
}
}
try
{
throw
e
;
throw
e
;
}
catch
(
ParserException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
}
}
}
System
.
out
.
println
(
Constants
.
Colors
.
YELLOW
+
"Program body statement count: "
+
programBody
.
size
()
+
Constants
.
Colors
.
RESET
);
},
"Parsing program body..."
);
ProgramStmt
program
=
new
ProgramStmt
(
1
,
programBody
);
ProgramStmt
program
=
new
ProgramStmt
(
1
,
programBody
);
this
.
print
(
"Parsed program: "
+
program
);
this
.
print
(
"Parsed program: "
+
program
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment