-
-
Notifications
You must be signed in to change notification settings - Fork 564
/
ShadowRealmBenchmark.cs
60 lines (50 loc) · 1.23 KB
/
ShadowRealmBenchmark.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
using BenchmarkDotNet.Attributes;
namespace Jint.Benchmark;
[MemoryDiagnoser]
[BenchmarkCategory("ShadowRealm")]
public class ShadowRealmBenchmark
{
private const string sourceCode = @"
(function (){return 'some string'})();
";
private Engine engine;
private Prepared<Script> parsedScript;
[GlobalSetup]
public void Setup()
{
engine = new Engine();
parsedScript = Engine.PrepareScript(sourceCode);
}
[Benchmark]
public void ReusingEngine()
{
engine.Evaluate(sourceCode);
}
[Benchmark]
public void NewEngineInstance()
{
new Engine().Evaluate(sourceCode);
}
[Benchmark]
public void ShadowRealm()
{
var shadowRealm = engine.Realm.Intrinsics.ShadowRealm.Construct();
shadowRealm.Evaluate(sourceCode);
}
[Benchmark]
public void ReusingEngine_ParsedScript()
{
engine.Evaluate(parsedScript);
}
[Benchmark]
public void NewEngineInstance_ParsedScript()
{
new Engine().Evaluate(parsedScript);
}
[Benchmark]
public void ShadowRealm_ParsedScript()
{
var shadowRealm = engine.Realm.Intrinsics.ShadowRealm.Construct();
shadowRealm.Evaluate(parsedScript);
}
}