ip2region_private/binding/c#/IP2Region.Test.Benchmark/TestBase.cs

52 lines
1.3 KiB
C#

using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
namespace IP2Region.Test.Benchmark
{
public class TestBase
{
protected DbSearcher _search;
private readonly string _dBFilePath = "";
public TestBase()
{
}
public TestBase(String DBFilePath)
{
this._dBFilePath = DBFilePath;
}
[GlobalSetup]
public void Init()
{
if (String.IsNullOrEmpty(_dBFilePath))
{
_search = new DbSearcher(AppContext.BaseDirectory + @"\DB\ip2region.db");
}
else
{
_search = new DbSearcher(_dBFilePath);
}
}
[GlobalCleanup]
public void Dispose()
{
_search?.Dispose();
}
public String GetRandomIP()
{
return new Random(Guid.NewGuid().GetHashCode()).Next(0, 255).ToString() + "."
+ new Random(Guid.NewGuid().GetHashCode()).Next(0, 255).ToString() + "."
+ new Random(Guid.NewGuid().GetHashCode()).Next(0, 255).ToString() + "."
+ new Random(Guid.NewGuid().GetHashCode()).Next(0, 255).ToString();
}
}
}