Skip to content

Commit

Permalink
Release 1 (1.1.0) (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakari-malkki authored Nov 14, 2024
2 parents b816ba4 + 2a35610 commit 763edd4
Showing 135 changed files with 9,250 additions and 4,196 deletions.
1 change: 1 addition & 0 deletions Px.Utils.TestingApp/Commands/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ internal BenchmarkRunner()
_benchmarks.Add("data-validation", new DataValidationBenchmark());
_benchmarks.Add("file-validation", new PxFileValidationBenchmark());
_benchmarks.Add("computation", new ComputationBenchmark());
_benchmarks.Add("database-validation", new DatabaseValidationBenchmark());
}

internal override string Help
50 changes: 25 additions & 25 deletions Px.Utils.TestingApp/Commands/DataReadBenchmark.cs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ internal sealed class DataReadBenchmark : FileBenchmark

internal override string Description => "Benchmarks the data reading capabilities of the PxFileStreamDataReader.";

private DataIndexer? Indexer { get; set; }
private IMatrixMap? Target { get; set; }

private int _numberOfCells = 1000000;

@@ -53,81 +53,81 @@ protected override void OneTimeBenchmarkSetup()
private void RunReadDoubleDataValuesBenchmarks()
{
if(MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

DoubleDataValue[] buffer = new DoubleDataValue[Indexer.DataLength];
DoubleDataValue[] buffer = new DoubleDataValue[Target.GetSize()];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

reader.ReadDoubleDataValues(buffer, 0, Indexer);
reader.ReadDoubleDataValues(buffer, 0, Target, MetaData);
}

private void RunReadDecimalDataValuesBenchmarks()
{
if (MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

DecimalDataValue[] buffer = new DecimalDataValue[Indexer.DataLength];
DecimalDataValue[] buffer = new DecimalDataValue[Target.GetSize()];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

reader.ReadDecimalDataValues(buffer, 0, Indexer);
reader.ReadDecimalDataValues(buffer, 0, Target, MetaData);
}

private void RunReadUnsafeDoubleBenchmarks()
{
if (MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

double[] buffer = new double[Indexer.DataLength];
double[] buffer = new double[Target.GetSize()];
double[] missingValueEncodings = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

reader.ReadUnsafeDoubles(buffer, 0, Indexer, missingValueEncodings);
reader.ReadUnsafeDoubles(buffer, 0, Target, MetaData, missingValueEncodings);
}

private async Task RunReadDoubleDataValuesBenchmarksAsync()
{
if (MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

DoubleDataValue[] buffer = new DoubleDataValue[Indexer.DataLength];
DoubleDataValue[] buffer = new DoubleDataValue[Target.GetSize()];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

await reader.ReadDoubleDataValuesAsync(buffer, 0, Indexer);
await reader.ReadDoubleDataValuesAsync(buffer, 0, Target, MetaData);
}

private async Task RunReadDecimalDataValuesBenchmarksAsync()
{
if (MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

DecimalDataValue[] buffer = new DecimalDataValue[Indexer.DataLength];
DecimalDataValue[] buffer = new DecimalDataValue[Target.GetSize()];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

await reader.ReadDecimalDataValuesAsync(buffer, 0, Indexer);
await reader.ReadDecimalDataValuesAsync(buffer, 0, Target, MetaData);
}

private async Task RunReadUnsafeDoubleBenchmarksAsync()
{
if (MetaData is null) throw new InvalidOperationException(metadataNotFoundMessage);
Indexer = GenerateBenchmarkIndexer(MetaData, _numberOfCells);
Target = GenerateBenchmarkTargetMap(MetaData, _numberOfCells);

double[] buffer = new double[Indexer.DataLength];
double[] buffer = new double[Target.GetSize()];
double[] missingValueEncodings = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0];

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
using PxFileStreamDataReader reader = new(stream);

await reader.ReadUnsafeDoublesAsync(buffer, 0, Indexer, missingValueEncodings);
await reader.ReadUnsafeDoublesAsync(buffer, 0, Target, MetaData, missingValueEncodings);
}

protected override void SetRunParameters()
@@ -143,12 +143,12 @@ protected override void SetRunParameters()
}
}

private static DataIndexer GenerateBenchmarkIndexer(IMatrixMap map, int targetSize)
private static IMatrixMap GenerateBenchmarkTargetMap(IMatrixMap complete, int targetSize)
{
int size = map.GetSize();
if (size < targetSize) return new DataIndexer(map, map);
int size = complete.GetSize();
if (size < targetSize) return complete;

List<IDimensionMap> sortedDimensions = [.. map.DimensionMaps];
List<IDimensionMap> sortedDimensions = [.. complete.DimensionMaps];
while (size > targetSize)
{
sortedDimensions = [.. sortedDimensions.OrderByDescending(x => x.ValueCodes.Count)];
@@ -157,15 +157,15 @@ private static DataIndexer GenerateBenchmarkIndexer(IMatrixMap map, int targetSi
size = sortedDimensions.Aggregate(1, (acc, x) => acc * x.ValueCodes.Count);
}

List<IDimensionMap> dimList = map.DimensionMaps
List<IDimensionMap> dimList = complete.DimensionMaps
.Select(dim => dim.Code)
.Select(dimCode => new DimensionMap(
dimCode,
[.. sortedDimensions.First(dim => dim.Code == dimCode).ValueCodes]))
.Cast<IDimensionMap>()
.ToList();

return new DataIndexer(map, new MatrixMap(dimList));
return new MatrixMap(dimList);
}
}
}
10 changes: 5 additions & 5 deletions Px.Utils.TestingApp/Commands/DataValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ protected override void OneTimeBenchmarkSetup()
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileMetadataReader reader = new();
encoding = reader.GetEncoding(stream);
start = StreamUtilities.FindKeywordPosition(stream, dataKeyword, PxFileSyntaxConf.Default);
start = StreamUtilities.FindKeywordPosition(stream, dataKeyword, PxFileConfiguration.Default);
if (start == -1)
{
throw new ArgumentException($"Could not find data keyword '{dataKeyword}'");
@@ -53,17 +53,17 @@ private void ValidateDataBenchmarks()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Position = start + dataKeyword.Length + readStartOffset; // skip the '=' and linechange
DataValidator validator = new(stream, expectedCols, expectedRows, TestFilePath, 0, encoding);
validator.Validate();
DataValidator validator = new(expectedCols, expectedRows, 0);
validator.Validate(stream, TestFilePath, encoding);
}

private async Task ValidateDataBenchmarksAsync()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Position = start + dataKeyword.Length + readStartOffset; // skip the '=' and linechange
DataValidator validator = new(stream, expectedCols, expectedRows, TestFilePath, 0, encoding);
DataValidator validator = new(expectedCols, expectedRows, 0);

await validator.ValidateAsync();
await validator.ValidateAsync(stream, TestFilePath, encoding);
}

protected override void SetRunParameters()
71 changes: 71 additions & 0 deletions Px.Utils.TestingApp/Commands/DatabaseValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Px.Utils.Validation.DatabaseValidation;

namespace Px.Utils.TestingApp.Commands
{
internal sealed class DatabaseValidationBenchmark : Benchmark
{
internal override string Help => "Validates a px path database.";

internal override string Description => "Validates a px path database.";
private static readonly string[] directoryFlags = ["-d", "-directory"];

private DatabaseValidator? validator;

internal DatabaseValidationBenchmark()
{
ParameterFlags.Add(directoryFlags);
BenchmarkFunctions = [ValidationBenchmark];
BenchmarkFunctionsAsync = [ValidationBenchmarkAsync];
}

protected override void SetRunParameters()
{
foreach (string key in directoryFlags)
{
if (Parameters.TryGetValue(key, out List<string>? value) && value.Count == 1)
{
TestFilePath = value[0];
base.SetRunParameters();
return;
}
}

throw new ArgumentException("Directory not found.");
}

protected override void StartInteractiveMode()
{
base.StartInteractiveMode();

Console.WriteLine("Enter the path to the PX database root to benchmark");
string path = Console.ReadLine() ?? "";

while (!Directory.Exists(path))
{
Console.WriteLine("Path provided is not valid, please enter a path to a valid directory.");
path = Console.ReadLine() ?? "";
}

TestFilePath = path;
}

protected override void OneTimeBenchmarkSetup()
{
base.OneTimeBenchmarkSetup();

validator = new(TestFilePath, new LocalFileSystem());
}

private void ValidationBenchmark()
{
if(validator is null) throw new InvalidOperationException("Validator not initialized.");
validator.Validate();
}

private async Task ValidationBenchmarkAsync()
{
if(validator is null) throw new InvalidOperationException("Validator not initialized.");
await validator.ValidateAsync();
}
}
}
2 changes: 1 addition & 1 deletion Px.Utils.TestingApp/Commands/FileBenchmark.cs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ protected override void SetRunParameters()
}
}

throw new ArgumentException("File path parameter not found for a file based benchmark.");
StartInteractiveMode();
}

protected override void StartInteractiveMode()
10 changes: 9 additions & 1 deletion Px.Utils.TestingApp/Commands/MetadataBuilderBenchmark.cs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ internal sealed class MetadataBuilderBenchmark : FileBenchmark
internal MetadataBuilderBenchmark()
{
BenchmarkFunctions = [BuildMetadata];
BenchmarkFunctionsAsync = [];
BenchmarkFunctionsAsync = [BuildMetadataAsync];
_metaEntries = [];
}

@@ -37,5 +37,13 @@ private void BuildMetadata()
IEnumerable<KeyValuePair<string, string>> copyMeta = [.. _metaEntries];
builder.Build(copyMeta);
}

private async Task BuildMetadataAsync()
{
var builder = new MatrixMetadataBuilder();
IEnumerable<KeyValuePair<string, string>> copyMeta = [.. _metaEntries];
IAsyncEnumerable<KeyValuePair<string, string>> copyMetaAsync = copyMeta.ToAsyncEnumerable();
await builder.BuildAsync(copyMetaAsync);
}
}
}
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ protected override void OneTimeBenchmarkSetup()

using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);
SyntaxValidator syntaxValidator = new(stream, Encoding.Default, TestFilePath);
SyntaxValidationResult validatorResult = syntaxValidator.Validate();
SyntaxValidator syntaxValidator = new();
SyntaxValidationResult validatorResult = syntaxValidator.Validate(stream, TestFilePath, Encoding.Default);
_entries = validatorResult.Result;
}

4 changes: 2 additions & 2 deletions Px.Utils.TestingApp/Commands/MetadataReaderBenchmark.cs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

namespace Px.Utils.TestingApp.Commands
{
internal sealed class MetadataReaderBenchmark : Benchmark
internal sealed class MetadataReaderBenchmark : FileBenchmark
{
internal override string Help => "Tests the performance of the metadata reading.";

@@ -29,7 +29,7 @@ private async Task BuildMetadataAsync()
{
using FileStream fileStream = new(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileMetadataReader reader = new();
Encoding encoding = reader.GetEncoding(fileStream);
Encoding encoding = await reader.GetEncodingAsync(fileStream);
fileStream.Seek(0, SeekOrigin.Begin);

_ = await reader.ReadMetadataAsync(fileStream, encoding).ToListAsync();
19 changes: 8 additions & 11 deletions Px.Utils.TestingApp/Commands/MetadataSyntaxValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

namespace Px.Utils.TestingApp.Commands
{
internal sealed class MetadataSyntaxValidationBenchmark : Benchmark
internal sealed class MetadataSyntaxValidationBenchmark : FileBenchmark
{
internal override string Help =>
"Validates the syntax of the Px file metadata given amount of times." + Environment.NewLine +
@@ -13,8 +13,7 @@ internal sealed class MetadataSyntaxValidationBenchmark : Benchmark

internal override string Description => "Benchmarks the metadata syntax validation of Px.Utils/Validation/SyntaxValidator.";

private Encoding encoding;
private SyntaxValidator validator;
private Encoding encoding = Encoding.Default;

internal MetadataSyntaxValidationBenchmark()
{
@@ -29,24 +28,22 @@ protected override void OneTimeBenchmarkSetup()
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
PxFileMetadataReader reader = new();
encoding = reader.GetEncoding(stream);
stream.Seek(0, SeekOrigin.Begin);
validator = new(stream, encoding, TestFilePath);
}

private void SyntaxValidationBenchmark()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);

validator.Validate();
SyntaxValidator validator = new();
validator.Validate(stream, TestFilePath, encoding);
stream.Close();
}

private async Task SyntaxValidationBenchmarkAsync()
{
using Stream stream = new FileStream(TestFilePath, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);

await validator.ValidateAsync();
SyntaxValidator validator = new();
await validator.ValidateAsync(stream, TestFilePath, encoding);
stream.Close();
}
}
}
Loading

0 comments on commit 763edd4

Please sign in to comment.