Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CachedRange<V> performance audit #19

Merged
merged 9 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
dotnet-version: |
3.1.x
6.0.x
7.0.x
- name: Build, Test, Pack, Publish
shell: bash
env:
Expand All @@ -47,6 +48,7 @@ jobs:
dotnet-version: |
3.1.x
6.0.x
7.0.x
- name: Build, Test, Pack, Publish
shell: pwsh
env:
Expand Down
18 changes: 18 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<Features>strict</Features>
<LangVersion>11</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<IsTrimmable>true</IsTrimmable>
<NoWarn>CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolySharp" Version="1.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
32 changes: 6 additions & 26 deletions src/FastCache.Benchmarks/Comparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,27 @@ public void Initialize()
[Benchmark(Baseline = true)]
public string TryGetCached()
{
if (Cached<string>.TryGet(ItemKey, out var cached))
{
return cached;
}

return Unreachable<string>();
return Cached<string>.TryGet(ItemKey, out var cached) ? cached : Unreachable<string>();
}

[Benchmark]
public string TryGetMemoryCache()
{
var found = _memoryCache.TryGetValue(ItemKey, out var cacheItem);
if (found && cacheItem is string value)
{
return value;
}

return Unreachable<string>();
return _memoryCache.TryGetValue(ItemKey, out var result) && result is string value
? value
: Unreachable<string>();
}

[Benchmark]
public string TryGetCacheManager()
{
var value = _cacheManager.Get(ItemKey);
if (value is not null)
{
return value;
}

return Unreachable<string>();
return _cacheManager.Get(ItemKey) ?? Unreachable<string>();
}

[Benchmark]
public string TryGetLazyCache()
{
if (_lazyCache.TryGetValue<string>(ItemKey, out var value))
{
return value;
}

return Unreachable<string>();
return _lazyCache.TryGetValue<string>(ItemKey, out var value) ? value : Unreachable<string>();
}

[Benchmark]
Expand Down
Loading