SunSpiderBenchmark.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using BenchmarkDotNet.Attributes;
  2. namespace Jint.Benchmark;
  3. [MemoryDiagnoser]
  4. public class SunSpiderBenchmark
  5. {
  6. private static readonly Dictionary<string, string> files = new()
  7. {
  8. {"3d-cube", null},
  9. {"3d-morph", null},
  10. {"3d-raytrace", null},
  11. {"access-binary-trees", null},
  12. {"access-fannkuch", null},
  13. {"access-nbody", null},
  14. {"access-nsieve", null},
  15. {"bitops-3bit-bits-in-byte", null},
  16. {"bitops-bits-in-byte", null},
  17. {"bitops-bitwise-and", null},
  18. {"bitops-nsieve-bits", null},
  19. {"controlflow-recursive", null},
  20. {"crypto-aes", null},
  21. {"crypto-md5", null},
  22. {"crypto-sha1", null},
  23. {"date-format-tofte", null},
  24. {"date-format-xparb", null},
  25. {"math-cordic", null},
  26. {"math-partial-sums", null},
  27. {"math-spectral-norm", null},
  28. {"regexp-dna", null},
  29. {"string-base64", null},
  30. {"string-fasta", null},
  31. {"string-tagcloud", null},
  32. {"string-unpack-code", null},
  33. {"string-validate-input", null}
  34. };
  35. private Engine engine;
  36. [GlobalSetup]
  37. public void Setup()
  38. {
  39. foreach (var fileName in files.Keys.ToList())
  40. {
  41. files[fileName] = File.ReadAllText($"Scripts/{fileName}.js");
  42. }
  43. engine = new Engine()
  44. .SetValue("log", new Action<object>(Console.WriteLine))
  45. .SetValue("assert", new Action<bool>(b => { }));
  46. }
  47. [ParamsSource(nameof(FileNames))]
  48. public string FileName { get; set; }
  49. public IEnumerable<string> FileNames()
  50. {
  51. foreach (var entry in files)
  52. {
  53. yield return entry.Key;
  54. }
  55. }
  56. [Benchmark]
  57. public void Run()
  58. {
  59. engine.Execute(files[FileName]);
  60. }
  61. }