SunSpiderBenchmark.cs 2.0 KB

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