1
+ // -----------------------------------------------------------------------
2
+ // <copyright file="ConfigFallbackLookupSpecs.cs" company="Akka.NET Project">
3
+ // Copyright (C) 2013 - 2020 .NET Foundation <https://github.com/akkadotnet/hocon>
4
+ // </copyright>
5
+ // -----------------------------------------------------------------------
6
+
7
+ using NBench ;
8
+
9
+ namespace Hocon . Tests . Performance
10
+ {
11
+ public class ConfigFallbackLookupSpecs
12
+ {
13
+ private const string LookupFallbackCounterName = "LookupFallbackOp" ;
14
+
15
+ private Counter _lookupFallbackOp ;
16
+
17
+ public static readonly Config C1 = @"
18
+ akka{
19
+ provider = cluster
20
+ remote.dot-netty.tcp.port = 8110
21
+ }
22
+ " ;
23
+
24
+ public static readonly Config C2 = @"
25
+ akka{
26
+ loglevel = DEBUG
27
+ remote.dot-netty.tcp.hostname = 0.0.0.0
28
+ }
29
+ " ;
30
+
31
+ public static readonly Config C3 = @"
32
+ akka{
33
+ remote.dot-netty.tcp.public-hostname = localhost
34
+ }
35
+ " ;
36
+
37
+ private static readonly Config L1 = C1 . WithFallback ( C2 ) ;
38
+
39
+ private static readonly Config L2 = C1 . WithFallback ( C3 ) ;
40
+
41
+ [ PerfSetup ]
42
+ public void Setup ( BenchmarkContext context )
43
+ {
44
+ _lookupFallbackOp = context . GetCounter ( LookupFallbackCounterName ) ;
45
+ }
46
+
47
+ [ PerfBenchmark (
48
+ Description = "Tests how quickly Config can be looked up from the second fallback" ,
49
+ RunMode = RunMode . Throughput , NumberOfIterations = 13 , RunTimeMilliseconds = 1000 ,
50
+ TestMode = TestMode . Measurement ) ]
51
+ [ CounterMeasurement ( LookupFallbackCounterName ) ]
52
+ [ GcMeasurement ( GcMetric . TotalCollections , GcGeneration . AllGc ) ]
53
+ [ MemoryMeasurement ( MemoryMetric . TotalBytesAllocated ) ]
54
+ public void Lookup_Config_Fallback_2_Deep ( BenchmarkContext context )
55
+ {
56
+ L1 . GetString ( "akka.loglevel" ) ;
57
+ _lookupFallbackOp . Increment ( ) ;
58
+ }
59
+
60
+ [ PerfBenchmark (
61
+ Description = "Tests how quickly Config can be looked up from the third fallback" ,
62
+ RunMode = RunMode . Throughput , NumberOfIterations = 13 , RunTimeMilliseconds = 1000 ,
63
+ TestMode = TestMode . Measurement ) ]
64
+ [ CounterMeasurement ( LookupFallbackCounterName ) ]
65
+ [ GcMeasurement ( GcMetric . TotalCollections , GcGeneration . AllGc ) ]
66
+ [ MemoryMeasurement ( MemoryMetric . TotalBytesAllocated ) ]
67
+ public void Lookup_Config_Fallback_3_Deep ( BenchmarkContext context )
68
+ {
69
+ L2 . GetString ( "akka.remote.dot-netty.tcp.public-hostname" ) ;
70
+ _lookupFallbackOp . Increment ( ) ;
71
+ }
72
+ }
73
+ }
0 commit comments