solve edge case
This commit is contained in:
parent
741d34a5e0
commit
0472bfe58e
15 changed files with 685 additions and 47 deletions
77
StitchATon2.Benchmark/SingleTileBenchmark.cs
Normal file
77
StitchATon2.Benchmark/SingleTileBenchmark.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using System.Net.Http.Json;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using StitchATon2.Domain;
|
||||
|
||||
namespace StitchATon2.Benchmark;
|
||||
|
||||
public class SingleTileBenchmark
|
||||
{
|
||||
private const string Url = "http://localhost:5088/api/image/generate";
|
||||
private readonly TileManager _tileManager = new(Configuration.Default);
|
||||
private readonly Random _random = new();
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
private string GetRandomCoordinatePair()
|
||||
{
|
||||
var maxId = _tileManager.Configuration.Rows
|
||||
* _tileManager.Configuration.Columns;
|
||||
|
||||
var id = _random.Next(maxId);
|
||||
var tile = _tileManager.GetTile(id);
|
||||
return $"{tile.Coordinate}:{tile.Coordinate}";
|
||||
}
|
||||
|
||||
private JsonContent GetRandomDto(float scale, float offsetX = 0, float offsetY = 0)
|
||||
{
|
||||
return JsonContent.Create(new
|
||||
{
|
||||
canvas_rect = GetRandomCoordinatePair(),
|
||||
crop_offset = (float[]) [offsetX, offsetY],
|
||||
crop_size = (float[]) [1f - offsetX, 1f - offsetY],
|
||||
output_scale = scale,
|
||||
});
|
||||
}
|
||||
|
||||
private JsonContent GetRandomDtoWithOffset(float scale)
|
||||
{
|
||||
var offsetX = _random.NextSingle();
|
||||
var offsetY = _random.NextSingle();
|
||||
return GetRandomDto(scale, offsetX, offsetY);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task NoScaling()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDto(1f));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task ScaleHalf()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDto(.5f));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task ScaleQuarter()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDto(.25f));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task NoScalingWithOffset()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDtoWithOffset(1f));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task ScaleHalfWithOffset()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDtoWithOffset(.5f));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task ScaleQuarterWithOffset()
|
||||
{
|
||||
await _client.PostAsync(Url, GetRandomDtoWithOffset(.25f));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue