|
|
@@ -1,4 +1,5 @@
|
|
|
using BenchmarkDotNet.Attributes;
|
|
|
+using Apq.Cfg.Env;
|
|
|
using Apq.Cfg.Ini;
|
|
|
using Apq.Cfg.Xml;
|
|
|
using Apq.Cfg.Yaml;
|
|
|
@@ -15,6 +16,7 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
{
|
|
|
private readonly string _testDir;
|
|
|
private ICfgRoot _jsonCfg = null!;
|
|
|
+ private ICfgRoot _envCfg = null!;
|
|
|
private ICfgRoot _iniCfg = null!;
|
|
|
private ICfgRoot _xmlCfg = null!;
|
|
|
private ICfgRoot _yamlCfg = null!;
|
|
|
@@ -50,6 +52,21 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
.AddJson(jsonPath, level: 0, writeable: true, isPrimaryWriter: true)
|
|
|
.Build();
|
|
|
|
|
|
+ // 创建 .env 配置文件
|
|
|
+ var envPath = Path.Combine(_testDir, ".env");
|
|
|
+ File.WriteAllText(envPath, """
|
|
|
+ DATABASE_HOST=localhost
|
|
|
+ DATABASE_PORT=5432
|
|
|
+ DATABASE_NAME=testdb
|
|
|
+ APP_NAME=BenchmarkApp
|
|
|
+ APP_VERSION=1.0.0
|
|
|
+ APP_MAXRETRIES=3
|
|
|
+ APP_ENABLED=true
|
|
|
+ """);
|
|
|
+ _envCfg = new CfgBuilder()
|
|
|
+ .AddEnv(envPath, level: 0, writeable: true, isPrimaryWriter: true)
|
|
|
+ .Build();
|
|
|
+
|
|
|
// 创建 INI 配置文件
|
|
|
var iniPath = Path.Combine(_testDir, "config.ini");
|
|
|
File.WriteAllText(iniPath, """
|
|
|
@@ -135,6 +152,7 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
public void Dispose()
|
|
|
{
|
|
|
_jsonCfg?.Dispose();
|
|
|
+ _envCfg?.Dispose();
|
|
|
_iniCfg?.Dispose();
|
|
|
_xmlCfg?.Dispose();
|
|
|
_yamlCfg?.Dispose();
|
|
|
@@ -152,6 +170,10 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
[BenchmarkCategory("Get")]
|
|
|
public string? Json_Get() => _jsonCfg.Get("Database:Host");
|
|
|
|
|
|
+ [Benchmark]
|
|
|
+ [BenchmarkCategory("Get")]
|
|
|
+ public string? Env_Get() => _envCfg.Get("DATABASE_HOST");
|
|
|
+
|
|
|
[Benchmark]
|
|
|
[BenchmarkCategory("Get")]
|
|
|
public string? Ini_Get() => _iniCfg.Get("Database:Host");
|
|
|
@@ -176,6 +198,10 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
[BenchmarkCategory("GetTyped")]
|
|
|
public int Json_GetInt() => _jsonCfg.Get<int>("Database:Port");
|
|
|
|
|
|
+ [Benchmark]
|
|
|
+ [BenchmarkCategory("GetTyped")]
|
|
|
+ public int Env_GetInt() => _envCfg.Get<int>("DATABASE_PORT");
|
|
|
+
|
|
|
[Benchmark]
|
|
|
[BenchmarkCategory("GetTyped")]
|
|
|
public int Ini_GetInt() => _iniCfg.Get<int>("Database:Port");
|
|
|
@@ -200,6 +226,10 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
[BenchmarkCategory("Exists")]
|
|
|
public bool Json_Exists() => _jsonCfg.Exists("Database:Host");
|
|
|
|
|
|
+ [Benchmark]
|
|
|
+ [BenchmarkCategory("Exists")]
|
|
|
+ public bool Env_Exists() => _envCfg.Exists("DATABASE_HOST");
|
|
|
+
|
|
|
[Benchmark]
|
|
|
[BenchmarkCategory("Exists")]
|
|
|
public bool Ini_Exists() => _iniCfg.Exists("Database:Host");
|
|
|
@@ -224,6 +254,10 @@ public class ReadWriteBenchmarks : IDisposable
|
|
|
[BenchmarkCategory("Set")]
|
|
|
public void Json_Set() => _jsonCfg.Set("App:TempKey", "TempValue");
|
|
|
|
|
|
+ [Benchmark]
|
|
|
+ [BenchmarkCategory("Set")]
|
|
|
+ public void Env_Set() => _envCfg.Set("APP_TEMPKEY", "TempValue");
|
|
|
+
|
|
|
[Benchmark]
|
|
|
[BenchmarkCategory("Set")]
|
|
|
public void Ini_Set() => _iniCfg.Set("App:TempKey", "TempValue");
|