-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
300 additions
and
143 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using Esprima; | ||
using Esprima.Ast; | ||
|
||
namespace Jint.Benchmark; | ||
|
||
[RankColumn] | ||
[MemoryDiagnoser] | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByParams)] | ||
[HideColumns("Error", "Gen0", "Gen1", "Gen2")] | ||
[BenchmarkCategory("EngineComparison")] | ||
public class EngineComparisonBenchmark | ||
{ | ||
private static readonly Dictionary<string, Script> _parsedScripts = new(); | ||
|
||
private static readonly Dictionary<string, string> _files = new() | ||
{ | ||
{ "array-stress", null }, | ||
{ "evaluation", null }, | ||
{ "linq-js", null }, | ||
{ "minimal", null }, | ||
{ "stopwatch", null }, | ||
{ "dromaeo-3d-cube", null }, | ||
{ "dromaeo-core-eval", null }, | ||
{ "dromaeo-object-array", null }, | ||
{ "dromaeo-object-regexp", null }, | ||
{ "dromaeo-object-string", null }, | ||
{ "dromaeo-string-base64", null }, | ||
}; | ||
|
||
private static readonly string _dromaeoHelpers = @" | ||
var startTest = function () { }; | ||
var test = function (name, fn) { fn(); }; | ||
var endTest = function () { }; | ||
var prep = function (fn) { fn(); };"; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var javaScriptParser = new JavaScriptParser(); | ||
foreach (var fileName in _files.Keys.ToList()) | ||
{ | ||
var script = File.ReadAllText($"Scripts/{fileName}.js"); | ||
if (fileName.Contains("dromaeo")) | ||
{ | ||
script = _dromaeoHelpers + Environment.NewLine + Environment.NewLine + script; | ||
} | ||
_files[fileName] = script; | ||
_parsedScripts[fileName] = javaScriptParser.ParseScript(script); | ||
} | ||
} | ||
|
||
[ParamsSource(nameof(FileNames))] | ||
public string FileName { get; set; } | ||
|
||
public IEnumerable<string> FileNames() | ||
{ | ||
return _files.Select(entry => entry.Key); | ||
} | ||
|
||
[Benchmark] | ||
public void Jint() | ||
{ | ||
var engine = new Engine(static options => options.Strict()); | ||
engine.Execute(_files[FileName]); | ||
} | ||
|
||
[Benchmark] | ||
public void Jint_ParsedScript() | ||
{ | ||
var engine = new Engine(static options => options.Strict()); | ||
engine.Execute(_parsedScripts[FileName]); | ||
} | ||
|
||
[Benchmark] | ||
public void Jurassic() | ||
{ | ||
var engine = new Jurassic.ScriptEngine { ForceStrictMode = true }; | ||
engine.Execute(_files[FileName]); | ||
} | ||
|
||
[Benchmark] | ||
public void NilJS() | ||
{ | ||
var engine = new NiL.JS.Core.Context(strict: true); | ||
engine.Eval(_files[FileName]); | ||
} | ||
|
||
[Benchmark] | ||
public void YantraJS() | ||
{ | ||
var engine = new YantraJS.Core.JSContext(); | ||
engine.Eval(_files[FileName]); | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var o = {}; | ||
o.Foo = 'bar'; | ||
o.Baz = 42.0001; | ||
o.Blah = o.Foo + o.Baz; | ||
|
||
if(o.Blah != 'bar42.0001') throw TypeError; | ||
|
||
function fib(n){ | ||
if(n<2) { | ||
return n; | ||
} | ||
|
||
return fib(n-1) + fib(n-2); | ||
} | ||
|
||
if(fib(3) != 2) throw TypeError; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
var x = 1 + 1 === 2; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
function Stopwatch() { | ||
var sw = this; | ||
var start = null; | ||
var stop = null; | ||
var isRunning = false; | ||
|
||
sw.Start = function () { | ||
if (isRunning) | ||
return; | ||
|
||
start = new Date(); | ||
stop = null; | ||
isRunning = true; | ||
} | ||
|
||
sw.Stop = function () { | ||
if (!isRunning) | ||
return; | ||
|
||
stop = new Date(); | ||
isRunning = false; | ||
} | ||
|
||
sw.Reset = function () { | ||
start = isRunning ? new Date() : null; | ||
stop = null; | ||
} | ||
|
||
sw.Restart = function () { | ||
isRunning = true; | ||
sw.Reset(); | ||
} | ||
|
||
sw.ElapsedMilliseconds = function () { return (isRunning ? new Date() : stop) - start; } | ||
sw.IsRunning = function() { return isRunning; } | ||
|
||
} | ||
|
||
var sw = new Stopwatch(); | ||
sw.Start(); | ||
for (var x = 0; x < 1021; x++) { | ||
for (var y = 0; y < 383; y++) { | ||
var z = x ^ y; | ||
if (z % 2 == 0) | ||
sw.Start(); | ||
else if(z % 3 == 0) | ||
sw.Stop(); | ||
else if (z % 5 == 0) | ||
sw.Reset(); | ||
else if (z % 7 == 0) | ||
sw.Restart(); | ||
var ms = sw.ElapsedMilliseconds; | ||
var rn = sw.IsRunning; | ||
} | ||
} | ||
sw.Stop(); |
Oops, something went wrong.