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