InterpreterSteps.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using BenchmarkDotNet.Attributes;
  2. using Lua;
  3. using Lua.Runtime;
  4. using Lua.Standard;
  5. [Config(typeof(BenchmarkConfig))]
  6. public class InterpreterSteps
  7. {
  8. string sourceText = default!;
  9. LuaState state = default!;
  10. LuaClosure closure = default!;
  11. [GlobalSetup]
  12. public void GlobalSetup()
  13. {
  14. var filePath = FileHelper.GetAbsolutePath("n-body.lua");
  15. sourceText = File.ReadAllText(filePath);
  16. state = LuaState.Create();
  17. state.OpenStandardLibraries();
  18. closure = state.Compile(sourceText,sourceText);
  19. }
  20. [IterationSetup]
  21. public void Setup()
  22. {
  23. state = default!;
  24. GC.Collect();
  25. state = LuaState.Create();
  26. state.OpenStandardLibraries();
  27. }
  28. [Benchmark]
  29. public void CreateState()
  30. {
  31. LuaState.Create();
  32. }
  33. [Benchmark]
  34. public LuaClosure Compile()
  35. {
  36. return state.Compile(sourceText, sourceText);
  37. }
  38. [Benchmark]
  39. public async ValueTask RunAsync()
  40. {
  41. using (await state.RunAsync(closure))
  42. {
  43. }
  44. }
  45. }