Browse Source

upgrade Esprima and BenchmarkDotNet (#468)

* add StopwatchBenchmark
* make benchmarks more reliable with longer run counts
Marko Lahma 7 years ago
parent
commit
c9531c3a59

+ 0 - 12
Jint.Benchmark/ArrayStressBenchmark.cs

@@ -1,21 +1,9 @@
 using BenchmarkDotNet.Attributes;
-using BenchmarkDotNet.Configs;
-using BenchmarkDotNet.Jobs;
 
 namespace Jint.Benchmark
 {
-    [Config(typeof(Config))]
     public class ArrayStressBenchmark : SingleScriptBenchmark
     {
-        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));
-            }
-        }
-
         protected override string Script => "var ret=[],tmp,num=100,i=256;for(var j1=0;j1<i*15;j1++){ret=[];ret.length=i}for(var j2=0;j2<i*10;j2++){ret=new Array(i)}ret=[];for(var j3=0;j3<i;j3++){ret.unshift(j3)}ret=[];for(var j4=0;j4<i;j4++){ret.splice(0,0,j4)}var a=ret.slice();for(var j5=0;j5<i;j5++){tmp=a.shift()}var b=ret.slice();for(var j6=0;j6<i;j6++){tmp=b.splice(0,1)}ret=[];for(var j7=0;j7<i*25;j7++){ret.push(j7)}var c=ret.slice();for(var j8=0;j8<i*25;j8++){tmp=c.pop()}var done = true;";
 
         [Params(20)]

+ 0 - 12
Jint.Benchmark/DromaeoBenchmark.cs

@@ -3,25 +3,13 @@ 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},

+ 1 - 1
Jint.Benchmark/Jint.Benchmark.csproj

@@ -18,8 +18,8 @@
     <None Include="..\Jint.Tests.CommonScripts\Scripts\**" CopyToOutputDirectory="PreserveNewest" LinkBase="SunSpider" />
   </ItemGroup>
   <ItemGroup>
+    <PackageReference Include="BenchmarkDotNet" Version="0.10.12" />
     <ProjectReference Include="..\Jint\Jint.csproj" />
-    <PackageReference Include="BenchmarkDotNet" Version="0.10.11" />
     <PackageReference Include="Jurassic" Version="3.0.0-alpha2" />
     <PackageReference Include="NiL.JS.NetCore" Version="2.5.1200" />
   </ItemGroup>

+ 71 - 0
Jint.Benchmark/StopwatchBenchmark.cs

@@ -0,0 +1,71 @@
+using BenchmarkDotNet.Attributes;
+
+namespace Jint.Benchmark
+{
+    public class StopwatchBenchmark : SingleScriptBenchmark
+    {
+        [Params(1)]
+        public override int N { get; set; }
+
+        protected override string Script => @"
+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();
+
+var done = true;
+";
+    }
+}

+ 0 - 12
Jint.Benchmark/SunSpiderBenchmark.cs

@@ -3,25 +3,13 @@ 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 SunSpiderBenchmark
     {
-        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>
         {
             {"3d-cube", null},

+ 1 - 1
Jint/Jint.csproj

@@ -6,6 +6,6 @@
     <SignAssembly>true</SignAssembly>
   </PropertyGroup>
   <ItemGroup>
-    <PackageReference Include="Esprima" Version="1.0.0-beta-1023" />
+    <PackageReference Include="Esprima" Version="1.0.0-beta-1025" />
   </ItemGroup>
 </Project>