From f1d0e1bee02122ec2a4f7cd5481fdd937bc19d8e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 21 Nov 2025 08:15:23 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20BenchMark=20?= =?UTF-8?q?=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IP2Region.Net.BenchMark.csproj | 12 ++++--- .../csharp/IP2Region.Net.BenchMark/Program.cs | 34 ++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/binding/csharp/IP2Region.Net.BenchMark/IP2Region.Net.BenchMark.csproj b/binding/csharp/IP2Region.Net.BenchMark/IP2Region.Net.BenchMark.csproj index 8d4f436..4060806 100644 --- a/binding/csharp/IP2Region.Net.BenchMark/IP2Region.Net.BenchMark.csproj +++ b/binding/csharp/IP2Region.Net.BenchMark/IP2Region.Net.BenchMark.csproj @@ -2,14 +2,14 @@ Exe - net9.0 + net10.0 enable enable - - + + @@ -21,6 +21,10 @@ IP2Region/ip2region_v4.xdb PreserveNewest - + + IP2Region/ip2region_v6.xdb + PreserveNewest + + diff --git a/binding/csharp/IP2Region.Net.BenchMark/Program.cs b/binding/csharp/IP2Region.Net.BenchMark/Program.cs index b079b8a..8cccb07 100644 --- a/binding/csharp/IP2Region.Net.BenchMark/Program.cs +++ b/binding/csharp/IP2Region.Net.BenchMark/Program.cs @@ -7,23 +7,41 @@ BenchmarkRunner.Run(typeof(Program).Assembly); public class CachePolicyCompare { - private static readonly string XdbPath = Path.Combine(AppContext.BaseDirectory, "IP2Region", "ip2region_v4.xdb"); - private readonly ISearcher _contentSearcher = new Searcher(CachePolicy.Content, XdbPath); - private readonly ISearcher _vectorSearcher = new Searcher(CachePolicy.VectorIndex,XdbPath); - private readonly ISearcher _fileSearcher = new Searcher(CachePolicy.File,XdbPath); + private static readonly string XdbPathV4 = Path.Combine(AppContext.BaseDirectory, "IP2Region", "ip2region_v4.xdb"); + private static readonly string XdbPathV6 = Path.Combine(AppContext.BaseDirectory, "IP2Region", "ip2region_v6.xdb"); + private readonly ISearcher _contentV4Searcher = new Searcher(CachePolicy.Content, XdbPathV4); + private readonly ISearcher _vectorV4Searcher = new Searcher(CachePolicy.VectorIndex, XdbPathV4); + private readonly ISearcher _fileV4Searcher = new Searcher(CachePolicy.File, XdbPathV4); + private readonly ISearcher _contentV6Searcher = new Searcher(CachePolicy.Content, XdbPathV6); + private readonly ISearcher _vectorV6Searcher = new Searcher(CachePolicy.VectorIndex, XdbPathV6); + private readonly ISearcher _fileV6Searcher = new Searcher(CachePolicy.File, XdbPathV6); - private readonly string _testIpAddress = "114.114.114.114"; + private readonly string _testIpV4Address = "114.114.114.114"; + private readonly string _testIpV6Address = "240e:3b7:3272:d8d0:db09:c067:8d59:539e"; [Benchmark] [BenchmarkCategory(nameof(CachePolicy.Content))] - public void CachePolicy_Content() => _contentSearcher.Search(_testIpAddress); + public void ContentIpV4() => _contentV4Searcher.Search(_testIpV4Address); [Benchmark] [BenchmarkCategory(nameof(CachePolicy.VectorIndex))] - public void CachePolicy_VectorIndex() => _vectorSearcher.Search(_testIpAddress); + public void VectorIndexIpV4() => _vectorV4Searcher.Search(_testIpV4Address); [Benchmark] [BenchmarkCategory(nameof(CachePolicy.File))] - public void CachePolicy_File() => _fileSearcher.Search(_testIpAddress); + public void FileIpV4() => _fileV4Searcher.Search(_testIpV4Address); + + [Benchmark] + [BenchmarkCategory(nameof(CachePolicy.Content))] + public void ContentIpV6() => _contentV6Searcher.Search(_testIpV6Address); + + [Benchmark] + [BenchmarkCategory(nameof(CachePolicy.VectorIndex))] + public void VectorIndexIpV6() => _vectorV6Searcher.Search(_testIpV6Address); + + + [Benchmark] + [BenchmarkCategory(nameof(CachePolicy.File))] + public void FileIpV6() => _fileV6Searcher.Search(_testIpV6Address); } \ No newline at end of file