Back to Ip2region

IP2Region.Net

binding/csharp/README.md

3.15.03.8 KB
Original Source

IP2Region.Net

.NET client library for IP2Region

Installation

Install the package with NuGet

bash
Install-Package IP2Region.Net

Usage

csharp
using IP2Region.Net.Abstractions;
using IP2Region.Net.XDB;

ISearcher searcher = new Searcher(CachePolicy , "your xdb file path");

Cache Policy Description

Cache PolicyDescriptionThread Safe
CachePolicy.ContentCache the entire xdb data.Yes
CachePolicy.VectorIndexCache vecotorIndex to speed up queries and reduce system io pressure by reducing one fixed IO operation.Yes
CachePolicy.FileCompletely file-based queriesYes

XDB File Description

Generate using maker, or download pre-generated xdb files

ASP.NET Core Usage

csharp
services.AddIP2RegionService("your xdb file path", cachePolicy: CachePolicy.Content);

NET6/7

csharp
provider.GetRequiredService<ISearcher>()

NET8+ support keyed service

csharp
provider.GetRequiredKeyedService<ISearcher>("IP2Region.Net");

TargetFrameworks

netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0;net10.0

Performance

// * Summary *

BenchmarkDotNet v0.15.6, Windows 11 (10.0.26200.7171) 13th Gen Intel Core i7-13700 2.10GHz, 1 CPU, 24 logical and 16 physical cores .NET SDK 10.0.100 [Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v3 DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v3

MethodMeanErrorStdDevGen0Allocated
ContentIPv453.70 ns0.296 ns0.277 ns0.0086136 B
VectorIPv44,446.04 ns18.673 ns15.593 ns0.0076232 B
FileIPv46,712.40 ns15.718 ns13.934 ns0.0153264 B
ContentIPv6145.53 ns0.331 ns0.277 ns0.0126200 B
VectorIPv67,058.39 ns125.505 ns117.398 ns0.0381712 B
FileIPv610,657.97 ns53.907 ns50.425 ns0.0458744 B

// * Hints * Outliers Benchmarks.VectorIPv4: Default -> 2 outliers were removed (4.55 us, 4.58 us) Benchmarks.FileIPv4: Default -> 1 outlier was removed (6.79 us) Benchmarks.ContentIPv6: Default -> 2 outliers were removed (148.08 ns, 152.27 ns)

// * Legends * Mean : Arithmetic mean of all measurements Error : Half of 99.9% confidence interval StdDev : Standard deviation of all measurements Gen0 : GC Generation 0 collects per 1000 operations Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B) 1 ns : 1 Nanosecond (0.000000001 sec)

// * Diagnostic Output - MemoryDiagnoser *

// ***** BenchmarkRunner: End ***** Run time: 00:02:06 (126.09 sec), executed benchmarks: 6

Global total time: 00:02:13 (133.47 sec), executed benchmarks: 6 // * Artifacts cleanup * Artifacts cleanup is finished

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache License 2.0