-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathClassBenchmark.cs
54 lines (48 loc) · 1.3 KB
/
ClassBenchmark.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
using BenchmarkDotNet.Attributes;
namespace Jint.Benchmark;
[MemoryDiagnoser]
public class ClassBenchmark
{
private Engine _engine;
[IterationSetup]
public void Setup()
{
_engine = new Engine();
_engine.Execute("""
class A { x = 1; };
class B extends A { y = 2; };
class C extends B { z = 3; };
class D extends C { x2 = 1; };
class E extends D { x3 = 1; };
class F extends E { x4 = 1; }
""");
_engine.Execute("const target = new F();");
}
[Benchmark]
public void ConstructSimple()
{
var script = Engine.PrepareScript("new A();");
for (var i = 0; i < 400_000; ++i)
{
_engine.Evaluate(script);
}
}
[Benchmark]
public void ConstructDeepInheritance()
{
var script = Engine.PrepareScript("new F();");
for (var i = 0; i < 80_000; ++i)
{
_engine.Evaluate(script);
}
}
[Benchmark]
public void GetSet()
{
var script = Engine.PrepareScript("target.x4 = 42; target.x4;");
for (var i = 0; i < 500_000; ++i)
{
_engine.Evaluate(script);
}
}
}