|
8 | 8 | using BenchmarkDotNet.Reports;
|
9 | 9 | using BenchmarkDotNet.Running;
|
10 | 10 | using Elastic.Clients.Elasticsearch;
|
| 11 | +using Elastic.Clients.Elasticsearch.Enrich; |
| 12 | +using Elastic.Clients.Elasticsearch.QueryDsl; |
11 | 13 | using Elastic.Transport;
|
12 | 14 | using Nest;
|
13 | 15 | using System.Globalization;
|
14 | 16 | using System.Text;
|
| 17 | +using Policy = Elastic.Clients.Elasticsearch.Enrich.Policy; |
15 | 18 |
|
16 | 19 | var config = ManualConfig.Create(DefaultConfig.Instance);
|
17 | 20 | config.SummaryStyle = new SummaryStyle(CultureInfo.CurrentCulture, true, BenchmarkDotNet.Columns.SizeUnit.B, null);
|
18 | 21 | config.AddDiagnoser(MemoryDiagnoser.Default);
|
19 | 22 |
|
20 | 23 | BenchmarkRunner.Run<Benchmarks.BulkIngest>(config);
|
21 | 24 |
|
| 25 | +//var thing = new Benchmarks.DescriptorValues(); |
| 26 | +//thing.Setup(); |
| 27 | + |
| 28 | +//var a = new EnrichPutPolicyRequestDescriptorV2<Benchmarks.SampleData>("test"); |
| 29 | + |
| 30 | +//a.Match(new Policy { Name = "test-name" }); |
| 31 | + |
| 32 | +//var settings = new ElasticsearchClientSettings(); |
| 33 | +//var serializer = new DefaultRequestResponseSerializer(settings); |
| 34 | +//var stream = new MemoryStream(); |
| 35 | + |
| 36 | +//serializer.Serialize(a, stream); |
| 37 | + |
| 38 | +//stream.Position = 0; |
| 39 | +//var sr = new StreamReader(stream); |
| 40 | +//var result = sr.ReadToEnd(); |
| 41 | + |
| 42 | +//Console.ReadKey(); |
| 43 | + |
22 | 44 | namespace Benchmarks
|
23 | 45 | {
|
| 46 | + //public class DescriptorValues |
| 47 | + //{ |
| 48 | + // private EnrichPutPolicyRequestDescriptor<SampleData>? _data1; |
| 49 | + // private EnrichPutPolicyRequestDescriptorV2<SampleData>? _data2; |
| 50 | + // private EnrichPutPolicyRequestDescriptorV3<SampleData>? _data3; |
| 51 | + // private EnrichPutPolicyRequestDescriptorV4<SampleData>? _data4; |
| 52 | + |
| 53 | + // //private Existing<SampleData>? _basicData1; |
| 54 | + // //private NewV1<SampleData>? _basicData2; |
| 55 | + // //private NewV2<SampleData>? _basicData3; |
| 56 | + |
| 57 | + // private readonly EnrichPutPolicyRequestDescriptor<SampleData> _existing = new("test"); |
| 58 | + // private readonly EnrichPutPolicyRequestDescriptorV2<SampleData> _newV1 = new("test"); |
| 59 | + // private readonly EnrichPutPolicyRequestDescriptorV3<SampleData> _newV2 = new("test"); |
| 60 | + // private readonly EnrichPutPolicyRequestDescriptorV4<SampleData> _newV3 = new("test"); |
| 61 | + // private readonly Policy? _policy = new() { Name = "TEST" }; |
| 62 | + |
| 63 | + // private readonly EnrichPutPolicyRequestDescriptor<SampleData> _serializableExisting = new("test"); |
| 64 | + // private readonly EnrichPutPolicyRequestDescriptorV2<SampleData> _serializableNewV1 = new("test"); |
| 65 | + // private readonly EnrichPutPolicyRequestDescriptorV3<SampleData> _serializableNewV2 = new("test"); |
| 66 | + // private readonly EnrichPutPolicyRequestDescriptorV4<SampleData> _serializableNewV3 = new("test"); |
| 67 | + |
| 68 | + // private static readonly ElasticsearchClientSettings Settings = new(); |
| 69 | + |
| 70 | + // private readonly DefaultRequestResponseSerializer _serializer = new(Settings); |
| 71 | + // private readonly MemoryStream _stream = new(); |
| 72 | + |
| 73 | + // [GlobalSetup] |
| 74 | + // public void Setup() |
| 75 | + // { |
| 76 | + // _serializableExisting.GeoMatch(_policy); |
| 77 | + // _serializableNewV1.GeoMatch(_policy); |
| 78 | + // _serializableNewV2.GeoMatch(_policy); |
| 79 | + // _serializableNewV3.GeoMatch(_policy); |
| 80 | + // } |
| 81 | + |
| 82 | + // [Benchmark] |
| 83 | + // public void Existing() => _data1 = new EnrichPutPolicyRequestDescriptor<SampleData>("name"); |
| 84 | + |
| 85 | + // [Benchmark] |
| 86 | + // public void NewV1() => _data2 = new EnrichPutPolicyRequestDescriptorV2<SampleData>("name"); |
| 87 | + |
| 88 | + // [Benchmark] |
| 89 | + // public void NewV2() => _data3 = new EnrichPutPolicyRequestDescriptorV3<SampleData>("name"); |
| 90 | + |
| 91 | + // [Benchmark] |
| 92 | + // public void NewV3() => _data4 = new EnrichPutPolicyRequestDescriptorV4<SampleData>("name"); |
| 93 | + |
| 94 | + // //[Benchmark] |
| 95 | + // //public void Existing() => _basicData1 = new Existing<SampleData>(); |
| 96 | + |
| 97 | + // //[Benchmark] |
| 98 | + // //public void NewV1() => _basicData2 = new NewV1<SampleData>(); |
| 99 | + |
| 100 | + // //[Benchmark] |
| 101 | + // //public void NewV2() => _basicData3 = new NewV2<SampleData>(); |
| 102 | + |
| 103 | + // [Benchmark] |
| 104 | + // public void SetExisting() => _existing.GeoMatch(_policy); |
| 105 | + |
| 106 | + // [Benchmark] |
| 107 | + // public void SetNewV1() => _newV1.GeoMatch(_policy); |
| 108 | + |
| 109 | + // [Benchmark] |
| 110 | + // public void SetNewV2() => _newV2.GeoMatch(_policy); |
| 111 | + |
| 112 | + // [Benchmark] |
| 113 | + // public void SetNewV3() => _newV3.GeoMatch(_policy); |
| 114 | + |
| 115 | + // [Benchmark] |
| 116 | + // public void SerialiseExisting() |
| 117 | + // { |
| 118 | + // _stream.Position = 0; |
| 119 | + // _serializer.Serialize(_serializableExisting, _stream); |
| 120 | + // } |
| 121 | + |
| 122 | + // [Benchmark] |
| 123 | + // public void SerialiseNewV1() |
| 124 | + // { |
| 125 | + // _stream.Position = 0; |
| 126 | + // _serializer.Serialize(_serializableNewV1, _stream); |
| 127 | + // } |
| 128 | + |
| 129 | + // [Benchmark] |
| 130 | + // public void SerialiseNewV2() |
| 131 | + // { |
| 132 | + // _stream.Position = 0; |
| 133 | + // _serializer.Serialize(_serializableNewV2, _stream); |
| 134 | + // } |
| 135 | + |
| 136 | + // [Benchmark] |
| 137 | + // public void SerialiseNewV3() |
| 138 | + // { |
| 139 | + // _stream.Position = 0; |
| 140 | + // _serializer.Serialize(_serializableNewV3, _stream); |
| 141 | + // } |
| 142 | + //} |
| 143 | + |
| 144 | + // RESULT OF ABOVE: |
| 145 | + //| Method | Mean [ns] | Error [ns] | StdDev [ns] | Gen 0 | Gen 1 | Allocated [B] | |
| 146 | + //|------------------ |-----------:|-----------:|------------:|-------:|-------:|--------------:| |
| 147 | + //| Existing | 116.408 ns | 2.1955 ns | 2.1563 ns | 0.0942 | 0.0002 | 592 B | |
| 148 | + //| NewV1 | 113.021 ns | 1.8475 ns | 1.8145 ns | 0.0943 | 0.0004 | 592 B | |
| 149 | + //| NewV2 | 115.728 ns | 2.2291 ns | 2.0851 ns | 0.0905 | 0.0002 | 568 B | |
| 150 | + //| NewV3 | 112.813 ns | 2.2198 ns | 3.1118 ns | 0.0867 | 0.0002 | 544 B | |
| 151 | + //| SetExisting | 1.688 ns | 0.0384 ns | 0.0340 ns | - | - | - | |
| 152 | + //| SetNewV1 | 2.200 ns | 0.0232 ns | 0.0217 ns | - | - | - | |
| 153 | + //| SetNewV2 | 2.555 ns | 0.0289 ns | 0.0256 ns | - | - | - | |
| 154 | + //| SetNewV3 | 1.691 ns | 0.0306 ns | 0.0286 ns | - | - | - | |
| 155 | + //| SerialiseExisting | 461.120 ns | 9.0066 ns | 8.4248 ns | 0.0687 | - | 432 B | |
| 156 | + //| SerialiseNewV1 | 472.239 ns | 8.4655 ns | 7.9186 ns | 0.0687 | - | 432 B | |
| 157 | + //| SerialiseNewV2 | 476.059 ns | 9.2350 ns | 10.2647 ns | 0.0687 | - | 432 B | |
| 158 | + //| SerialiseNewV3 | 483.717 ns | 9.5424 ns | 8.9260 ns | 0.0687 | - | 432 B | |
| 159 | + |
24 | 160 | public class BulkIngest
|
25 | 161 | {
|
26 | 162 | //private static readonly List<SampleData> Data = Enumerable.Range(0, 100).Select(r => new SampleData()).ToList();
|
|
0 commit comments