Permalink
Browse files

#451 fix string.split and array.join performance (#462)

* String.split should not to create new list
* Array.join should use StringBuilder
* add dromaeo benchmarks
  • Loading branch information...
lahma authored and sebastienros committed Jan 9, 2018
1 parent f5f4329 commit a3c5cb18bf00d3cb6c9626814afe0aec8cd23b60
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using Jint;
namespace Esprima.Benchmark
{
[Config(typeof(Config))]
[MemoryDiagnoser]
public class DromaeoBenchmark
{
private class Config : ManualConfig
{
public Config()
{
// if Jint array performance gets better we can go towards defaul 16/16
Add(Job.ShortRun.WithInvocationCount(4).WithUnrollFactor(4));
}
}
private static readonly Dictionary<string, string> files = new Dictionary<string, string>
{
{"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 Engine engine;
[GlobalSetup]
public void Setup()
{
foreach (var fileName in files.Keys.ToList())
{
files[fileName] = File.ReadAllText($"Scripts/dromaeo/{fileName}.js");
}
engine = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("assert", new Action<bool>(b => { }));
engine.Execute(@"
var startTest = function () { };
var test = function (name, fn) { fn(); };
var endTest = function () { };
var prep = function (fn) { fn(); };
");
}
[ParamsSource(nameof(FileNames))]
public string FileName { get; set; }
public IEnumerable<string> FileNames()
{
foreach (var entry in files)
{
yield return entry.Key;
}
}
[Benchmark]
public void Run()
{
engine.Execute(files[FileName]);
}
}
}
@@ -14,6 +14,7 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>
<ItemGroup>
<None Include=".\Scripts\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="..\Jint.Tests.CommonScripts\Scripts\**" CopyToOutputDirectory="PreserveNewest" LinkBase="SunSpider" />
</ItemGroup>
<ItemGroup>
Oops, something went wrong.

0 comments on commit a3c5cb1

Please sign in to comment.