Skip to content

Commit fce77d6

Browse files
Add CacheKey benchmarks
1 parent f646f03 commit fce77d6

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

tests/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ItemGroup>
2121
<PackageReference Update="Azure.Storage.Blobs" Version="12.10.0" />
2222
<PackageReference Update="BenchmarkDotNet" Version="0.13.1" />
23+
<PackageReference Update="Microsoft.AspNetCore.Http" Version="2.2.2" />
2324
<PackageReference Update="Microsoft.Azure.KeyVault.Core" Version="3.0.4" />
2425
<PackageReference Update="Microsoft.Azure.Storage.Blob" Version="11.1.2" />
2526

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using BenchmarkDotNet.Attributes;
6+
using Microsoft.AspNetCore.Http;
7+
using SixLabors.ImageSharp.Web.Caching;
8+
using SixLabors.ImageSharp.Web.Commands;
9+
10+
namespace SixLabors.ImageSharp.Web.Benchmarks.Caching
11+
{
12+
[Config(typeof(MemoryConfig))]
13+
public class CacheKeyBenchmarks
14+
{
15+
private static readonly HttpContext Context = CreateContext();
16+
private static readonly CommandCollection Commands = new()
17+
{
18+
{ "width", "400" }
19+
};
20+
21+
private static readonly ICacheKey UriRelativeCacheKey = new UriRelativeCacheKey();
22+
private static readonly ICacheKey UriAbsoluteCacheKey = new UriAbsoluteCacheKey();
23+
24+
[Benchmark(Baseline = true, Description = "UriRelativeCacheKey")]
25+
public string CreateUsingUriRelativeCacheKey() => UriRelativeCacheKey.Create(Context, Commands);
26+
27+
[Benchmark(Description = "UriAbsoluteCacheKey")]
28+
public string CreateUsingUriAbsoluteCacheKey() => UriAbsoluteCacheKey.Create(Context, Commands);
29+
30+
private static HttpContext CreateContext()
31+
{
32+
var httpContext = new DefaultHttpContext();
33+
httpContext.Request.Scheme = Uri.UriSchemeHttp;
34+
httpContext.Request.Host = new HostString("testwebsite.com");
35+
httpContext.Request.PathBase = "/images";
36+
httpContext.Request.Path = "/image-12345.jpeg";
37+
httpContext.Request.QueryString = new QueryString("?should-be=ignored");
38+
39+
return httpContext;
40+
}
41+
}
42+
}

tests/ImageSharp.Web.Benchmarks/ImageSharp.Web.Benchmarks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="BenchmarkDotNet"/>
15+
<PackageReference Include="Microsoft.AspNetCore.Http"/>
1516
</ItemGroup>
1617

1718
<ItemGroup>

0 commit comments

Comments
 (0)