-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize engine construction (#1621)
- Loading branch information
Showing
11 changed files
with
256 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Esprima; | ||
using Esprima.Ast; | ||
using Jint.Native; | ||
|
||
namespace Jint.Benchmark; | ||
|
||
[MemoryDiagnoser] | ||
public class EngineConstructionBenchmark | ||
{ | ||
private readonly Script _program; | ||
private Script _program; | ||
private Script _simple; | ||
|
||
public EngineConstructionBenchmark() | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var parser = new JavaScriptParser(); | ||
_program = parser.ParseScript("return [].length + ''.length"); | ||
_program = parser.ParseScript("([].length + ''.length)"); | ||
_simple = parser.ParseScript("1"); | ||
new Engine().Evaluate(_program); | ||
} | ||
|
||
[Benchmark] | ||
public double BuildEngine() | ||
public Engine BuildEngine() | ||
{ | ||
var engine = new Engine(); | ||
return engine.Evaluate(_program).AsNumber(); | ||
return engine; | ||
} | ||
|
||
[Benchmark] | ||
public JsValue EvaluateSimple() | ||
{ | ||
var engine = new Engine(); | ||
return engine.Evaluate(_simple); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.