-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: BinarySpace <29510799+YetAnotherBinarySpace@users.noreply.github.com> Co-Authored-By: Luzifix <7042325+luzifix@users.noreply.github.com>
- Loading branch information
1 parent
25224bb
commit 7dd1077
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using DBCD.Benchmark.Utilities; | ||
using DBCD.Providers; | ||
|
||
namespace DBCD.Benchmark.Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class WritingBenchmark | ||
{ | ||
public static GithubDBDProvider DBDProvider { get; } = new GithubDBDProvider(true); | ||
public static string InputPath { get; } = $"{Directory.GetCurrentDirectory()}\\dbc"; | ||
public static DBCD InputDBCD { get; } = new DBCD(new FilesystemDBCProvider(InputPath), DBDProvider); | ||
public static DBCD SavedDBCD { get; } = new DBCD(new FilesystemDBCProvider("tmp"), DBDProvider); | ||
|
||
public static string Build { get; } = "9.1.0.39653"; | ||
|
||
[Benchmark] | ||
public void TestWritingAllDB2s() | ||
{ | ||
string[] allDB2s = Directory.GetFiles(InputPath, "*.db2", SearchOption.TopDirectoryOnly); | ||
|
||
if (Directory.Exists("tmp")) | ||
Directory.Delete("tmp", true); | ||
Directory.CreateDirectory("tmp"); | ||
|
||
foreach (var db2File in allDB2s) | ||
{ | ||
if (Utilities.IO.TryGetExactPath(db2File, out string exactPath)) | ||
{ | ||
var tableName = Path.GetFileNameWithoutExtension(exactPath); | ||
|
||
var originalStorage = InputDBCD.Load(tableName, Build); | ||
originalStorage.Save($"tmp/{tableName}.db2"); | ||
} | ||
} | ||
|
||
Directory.Delete("tmp", true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DBCD\DBCD.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using BenchmarkDotNet.Running; | ||
using DBCD.Benchmark.Benchmarks; | ||
|
||
BenchmarkRunner.Run<WritingBenchmark>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace DBCD.Benchmark.Utilities | ||
{ | ||
internal class IO | ||
{ | ||
public static bool TryGetExactPath(string path, out string exactPath) | ||
{ | ||
bool result = false; | ||
exactPath = null; | ||
|
||
// DirectoryInfo accepts either a file path or a directory path, and most of its properties work for either. | ||
// However, its Exists property only works for a directory path. | ||
DirectoryInfo directory = new DirectoryInfo(path); | ||
if (File.Exists(path) || directory.Exists) | ||
{ | ||
List<string> parts = new List<string>(); | ||
|
||
DirectoryInfo parentDirectory = directory.Parent; | ||
while (parentDirectory != null) | ||
{ | ||
FileSystemInfo entry = parentDirectory.EnumerateFileSystemInfos(directory.Name).First(); | ||
parts.Add(entry.Name); | ||
|
||
directory = parentDirectory; | ||
parentDirectory = directory.Parent; | ||
} | ||
|
||
// Handle the root part (i.e., drive letter or UNC \\server\share). | ||
string root = directory.FullName; | ||
if (root.Contains(':')) | ||
{ | ||
root = root.ToUpper(); | ||
} | ||
else | ||
{ | ||
string[] rootParts = root.Split('\\'); | ||
root = string.Join("\\", rootParts.Select(part => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(part))); | ||
} | ||
|
||
parts.Add(root); | ||
parts.Reverse(); | ||
exactPath = Path.Combine(parts.ToArray()); | ||
result = true; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters