-
Notifications
You must be signed in to change notification settings - Fork 42
/
FileWatchingBenchmarks.cs
63 lines (54 loc) · 2.54 KB
/
FileWatchingBenchmarks.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
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
namespace Jering.Javascript.NodeJS.Performance
{
[MemoryDiagnoser]
public class FileWatchingBenchmarks
{
private const string DUMMY_WARMUP_MODULE = "module.exports = (callback) => callback()";
private const string DUMMY_PATH = "dummyPath";
private ServiceProvider? _serviceProvider;
private HttpNodeJSService? _httpNodeJSService;
[GlobalSetup(Target = nameof(HttpNodeJSService_FileWatching_GracefulShutdownEnabled_MoveToNewProcess))]
public void HttpNodeJSService_FileWatching_GracefulShutdownEnabled_MoveToNewProcess_Setup()
{
var services = new ServiceCollection();
services.AddNodeJS();
services.Configure<OutOfProcessNodeJSServiceOptions>(options => options.EnableFileWatching = true);
_serviceProvider = services.BuildServiceProvider();
_httpNodeJSService = _serviceProvider.GetRequiredService<INodeJSService>() as HttpNodeJSService;
// Warmup. First run starts a Node.js process.
_httpNodeJSService!.InvokeFromStringAsync(DUMMY_WARMUP_MODULE).GetAwaiter().GetResult();
}
[Benchmark]
public void HttpNodeJSService_FileWatching_GracefulShutdownEnabled_MoveToNewProcess()
{
_httpNodeJSService!.FileChangedHandler();
}
[GlobalSetup(Target = nameof(HttpNodeJSService_FileWatching_GracefulShutdownDisabled_MoveToNewProcess))]
public void HttpNodeJSService_FileWatching_GracefulShutdownDisabled_MoveToNewProcess_Setup()
{
var services = new ServiceCollection();
services.AddNodeJS();
services.Configure<OutOfProcessNodeJSServiceOptions>(options =>
{
options.EnableFileWatching = true;
options.GracefulProcessShutdown = false;
});
_serviceProvider = services.BuildServiceProvider();
_httpNodeJSService = _serviceProvider.GetRequiredService<INodeJSService>() as HttpNodeJSService;
// Warmup. First run starts a Node.js process.
_httpNodeJSService!.InvokeFromStringAsync(DUMMY_WARMUP_MODULE).GetAwaiter().GetResult();
}
[Benchmark]
public void HttpNodeJSService_FileWatching_GracefulShutdownDisabled_MoveToNewProcess()
{
_httpNodeJSService!.FileChangedHandler();
}
[GlobalCleanup]
public void Cleanup()
{
_serviceProvider?.Dispose();
}
}
}