Browse Source

Add: benchmark to README

AnnulusGames 1 year ago
parent
commit
782fadf509

+ 5 - 1
README.md

@@ -14,7 +14,11 @@ English | [日本語](README_JA.md)
 
 Lua-CSharp is a library that provides a Lua interpreter implemented in C#. By integrating Lua-CSharp, you can easily embed Lua scripts into your .NET applications.
 
-// TODO: Add benchmarks
+Lua-CSharp leverages the latest C# features, designed with low allocation and high performance in mind. It is optimized to deliver maximum performance when used for interoperation between C# and Lua in C# applications. Below is a benchmark comparison with MoonSharp and NLua:
+
+![img](docs/Benchmark.png)
+
+MoonSharp generally provides good speed but incurs significant allocations due to its design. NLua, being a C-binding implementation, is fast, but introduces substantial overhead when interacting with the C# layer. Lua-CSharp, fully implemented in C#, allows for seamless interaction with C# code without additional overhead. Moreover, it operates reliably in AOT environments since it does not rely on IL generation.
 
 ## Features
 

+ 5 - 1
README_JA.md

@@ -14,7 +14,11 @@ High performance Lua interpreter implemented in C# for .NET and Unity
 
 Lua-CSharpはC#実装のLuaインタプリタを提供するライブラリです。Lua-CSharpを導入することで、.NETアプリケーション内で簡単にLuaスクリプトを組み込むことが可能になります。
 
-// TODO: ベンチマークの追加
+Lua-CSharpは最新のC#の機能を活用し、低アロケーション・ハイパフォーマンスを念頭において設計されています。Lua-CSharpはC#アプリケーションに組み込まれることを前提としているため、C#-Lua間の相互運用時に最大のパフォーマンスを発揮するように最適化されています。以下は[MoonSharp](https://github.com/moonsharp-devs/moonsharp/), [NLua](https://github.com/NLua/NLua)と比較したベンチマークです。
+
+![img](docs/Benchmark.png)
+
+MoonSharpは多くの場合で十分な速度を発揮しますが、設計上非常に大きいアロケーションが発生します。NLuaはCバインディングであるため動作そのものは高速ですが、C#レイヤーとのやり取りの際に大きなオーバーヘッドがかかります。Lua-CSharpは完全にC#で実装されているため、C#コードとオーバーヘッドなしでやり取りが可能です。また、IL生成などを一切使用しないためAOT環境でも安定して動作します。
 
 ## 特徴
 

BIN
docs/Benchmark.png


+ 0 - 13
sandbox/Benchmark/AddBenchmark.cs

@@ -29,7 +29,6 @@ public class AddBenchmark
         });
         core.MoonSharpState.Globals["add"] = (Func<double, double, double>)Add;
         core.NLuaState.RegisterFunction("add", typeof(AddBenchmark).GetMethod(nameof(Add), BindingFlags.Static | BindingFlags.Public));
-        core.NeoLuaEnvironment.SetValue("add", (Func<double, double, double>)Add);
     }
 
     [IterationCleanup]
@@ -64,18 +63,6 @@ public class AddBenchmark
         return core.NLuaState.DoFile(core.FilePath);
     }
 
-    [Benchmark(Description = "NeoLua (DoChunk(code))")]
-    public Neo.IronLua.LuaResult Benchmark_NeoLua_String()
-    {
-        return core.NeoLuaEnvironment.DoChunk(core.SourceText, "chunk");
-    }
-
-    [Benchmark(Description = "NeoLua (DoChunk(fileName))")]
-    public Neo.IronLua.LuaResult Benchmark_NeoLua_File()
-    {
-        return core.NeoLuaEnvironment.DoChunk(core.FilePath);
-    }
-
     [Benchmark(Description = "Lua-CSharp (DoString)")]
     public async Task<LuaValue> Benchmark_LuaCSharp_String()
     {

+ 0 - 1
sandbox/Benchmark/Benchmark.csproj

@@ -10,7 +10,6 @@
   <ItemGroup>
     <PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
     <PackageReference Include="MoonSharp" Version="2.0.0" />
-    <PackageReference Include="NeoLua" Version="1.3.14" />
     <PackageReference Include="NLua" Version="1.7.3" />
   </ItemGroup>
 

+ 0 - 8
sandbox/Benchmark/BenchmarkCore.cs

@@ -4,15 +4,12 @@ using MoonSharp.Interpreter;
 public class BenchmarkCore : IDisposable
 {
     public NLua.Lua NLuaState => nLuaState;
-    public Neo.IronLua.LuaGlobal NeoLuaEnvironment => neoLuaEnvironment;
     public Script MoonSharpState => moonSharpState;
     public LuaState LuaCSharpState => luaCSharpState;
     public string FilePath => filePath;
     public string SourceText => sourceText;
 
     NLua.Lua nLuaState = default!;
-    Neo.IronLua.Lua neoLuaState = default!;
-    Neo.IronLua.LuaGlobal neoLuaEnvironment = default!;
     Script moonSharpState = default!;
     LuaState luaCSharpState = default!;
     string filePath = default!;
@@ -27,10 +24,6 @@ public class BenchmarkCore : IDisposable
         // NLua
         nLuaState = new();
 
-        // NeoLua
-        neoLuaState = new();
-        neoLuaEnvironment = neoLuaState.CreateEnvironment();
-
         // Lua-CSharp
         luaCSharpState = LuaState.Create();
 
@@ -41,6 +34,5 @@ public class BenchmarkCore : IDisposable
     public void Dispose()
     {
         nLuaState.Dispose();
-        neoLuaState.Dispose();
     }
 }

+ 0 - 12
sandbox/Benchmark/NBodyBenchmark.cs

@@ -49,18 +49,6 @@ public class NBodyBenchmark
         return core.NLuaState.DoFile(core.FilePath);
     }
 
-    [Benchmark(Description = "NeoLua (DoChunk(code))")]
-    public Neo.IronLua.LuaResult Benchmark_NeoLua_String()
-    {
-        return core.NeoLuaEnvironment.DoChunk(core.SourceText, "chunk");
-    }
-
-    [Benchmark(Description = "NeoLua (DoChunk(fileName))")]
-    public Neo.IronLua.LuaResult Benchmark_NeoLua_File()
-    {
-        return core.NeoLuaEnvironment.DoChunk(core.FilePath);
-    }
-
     [Benchmark(Description = "Lua-CSharp (DoString)")]
     public async Task<LuaValue> Benchmark_LuaCSharp_String()
     {