General Performance Best Practices #1856
julianhall
started this conversation in
General
Replies: 2 comments 3 replies
-
Just two things I do:
|
Beta Was this translation helpful? Give feedback.
2 replies
-
I'd suggest measuring your specific use cases. I'm not familiar with EcmaScript.NET, but I run our standard engine comparison benchmark like so (regex test was stuck against EcmaScript.NET so skipped it): using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Order;
namespace Jint.Benchmark;
[RankColumn]
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByParams)]
[HideColumns("Error", "Gen0", "Gen1", "Gen2")]
[BenchmarkCategory("EngineComparison")]
public class EngineComparisonBenchmark
{
private static readonly Dictionary<string, Prepared<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()
{
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] = Engine.PrepareScript(script, strict: true);
}
}
[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(Baseline = true)]
public void EcmaScriptNet()
{
var engine = EcmaScript.NET.Context.Enter();
var scope = engine.InitStandardObjects();
engine.EvaluateString(scope, _files[FileName], FileName, 0, null);
}
} And got results:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi -
We've been following this project for a while (well close to a decade!). We've implemented a few POC's in attempt to replace our internal JavaScript engine from, i believe, this one (https://github.com/PureKrome/EcmaScript.NET). It's ancient and we need to replace our internal js engine in our .NET web app. (proprietary language believe it or not...)
I'm looking to see if anyone has some general guidance on improving performance. Here are some details:
Thanks in advance.
Jules
Beta Was this translation helpful? Give feedback.
All reactions