Skip to content

Commit fb72152

Browse files
authored
Added net6.0 target. Bumped BenchmarkDotNet version to 0.13.1 (#50)
1 parent 51e4204 commit fb72152

5 files changed

Lines changed: 68 additions & 57 deletions

File tree

src/Hashids.net/Hashids.net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageTags>ids;hash</PackageTags>
1414
<RepositoryType>git</RepositoryType>
1515
<RepositoryUrl>https://github.com/ullmark/hashids.net</RepositoryUrl>
16-
<TargetFrameworks>net461;net5.0;netstandard2.0</TargetFrameworks>
16+
<TargetFrameworks>net461;netstandard2.0;net5.0;net6.0</TargetFrameworks>
1717
<OutputType>Library</OutputType>
1818
<LangVersion>9</LangVersion>
1919
<IncludeSymbols>true</IncludeSymbols>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Jobs;
4+
5+
namespace Hashids.net.benchmark
6+
{
7+
[MemoryDiagnoser]
8+
[MemoryRandomization]
9+
[DisassemblyDiagnoser]
10+
[SimpleJob(RuntimeMoniker.Net48)]
11+
[SimpleJob(RuntimeMoniker.Net50)]
12+
[SimpleJob(RuntimeMoniker.Net60)]
13+
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByJob)]
14+
public class HashBenchmarks
15+
{
16+
private readonly HashidsNet.Hashids _hashids;
17+
private readonly int[] _ints = { 12345, 1234567890, int.MaxValue };
18+
private readonly long[] _longs = { 12345, 1234567890123456789, long.MaxValue };
19+
private readonly string _hex = "507f1f77bcf86cd799439011";
20+
21+
public HashBenchmarks()
22+
{
23+
_hashids = new HashidsNet.Hashids();
24+
}
25+
26+
[Benchmark]
27+
public void RoundtripInts()
28+
{
29+
var encodedValue = _hashids.Encode(_ints);
30+
var decodedValue = _hashids.Decode(encodedValue);
31+
}
32+
33+
[Benchmark]
34+
public void RoundtripLongs()
35+
{
36+
var encodedValue = _hashids.EncodeLong(_longs);
37+
var decodedValue = _hashids.DecodeLong(encodedValue);
38+
}
39+
40+
[Benchmark]
41+
public void RoundtripHex()
42+
{
43+
var encodedValue = _hashids.EncodeHex(_hex);
44+
var decodedValue = _hashids.DecodeHex(encodedValue);
45+
}
46+
47+
[Benchmark]
48+
public void SingleNumber()
49+
{
50+
var encoded = _hashids.Encode(5);
51+
var encodeLong = _hashids.EncodeLong(5);
52+
}
53+
54+
[Benchmark]
55+
public void SingleNumberAsParams()
56+
{
57+
var encoded = _hashids.Encode(new[] { 1 });
58+
var encodedLong = _hashids.EncodeLong(new[] { (long)1 });
59+
}
60+
}
61+
}

test/Hashids.net.benchmark/Hashids.net.benchmark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,12 @@
1-
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Running;
1+
using BenchmarkDotNet.Running;
32

43
namespace Hashids.net.benchmark
54
{
65
public class Program
76
{
87
public static void Main(string[] args)
98
{
10-
var summary = BenchmarkRunner.Run<HashBenchmark>();
11-
}
12-
13-
[MemoryDiagnoser]
14-
public class HashBenchmark
15-
{
16-
private readonly HashidsNet.Hashids _hashids;
17-
private readonly int[] _ints = { 12345, 1234567890, int.MaxValue };
18-
private readonly long[] _longs = { 12345, 1234567890123456789, long.MaxValue };
19-
private readonly string _hex = "507f1f77bcf86cd799439011";
20-
21-
public HashBenchmark()
22-
{
23-
_hashids = new HashidsNet.Hashids();
24-
}
25-
26-
[Benchmark]
27-
public void RoundtripInts()
28-
{
29-
var encodedValue = _hashids.Encode(_ints);
30-
var decodedValue = _hashids.Decode(encodedValue);
31-
}
32-
33-
[Benchmark]
34-
public void RoundtripLongs()
35-
{
36-
var encodedValue = _hashids.EncodeLong(_longs);
37-
var decodedValue = _hashids.DecodeLong(encodedValue);
38-
}
39-
40-
[Benchmark]
41-
public void RoundtripHex()
42-
{
43-
var encodedValue = _hashids.EncodeHex(_hex);
44-
var decodedValue = _hashids.DecodeHex(encodedValue);
45-
}
46-
47-
[Benchmark]
48-
public void SingleNumber()
49-
{
50-
var encoded = _hashids.Encode(5);
51-
var encodeLong = _hashids.EncodeLong(5);
52-
}
53-
54-
[Benchmark]
55-
public void SingleNumberAsParams()
56-
{
57-
var encoded = _hashids.Encode(new []{ 1 });
58-
var encodedLong = _hashids.EncodeLong(new []{ (long)1 });
59-
}
9+
var summary = BenchmarkRunner.Run<HashBenchmarks>();
6010
}
6111
}
6212
}

test/Hashids.net.test/Hashids.net.test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
<PropertyGroup>
44
<!--
5-
The main project targets net461, net5.0, and netstandard2.0.
5+
The main project targets net461, netstandard2.0, net5.0 and net6.0
66
As test projects cannot target netstandard the net48 target is used as a stand-in for that.
77
-->
8-
<TargetFrameworks>net461;net48;net5.0</TargetFrameworks>
8+
<TargetFrameworks>net461;net48;net5.0;net6.0</TargetFrameworks>
99
<IsPackable>false</IsPackable>
1010
<LangVersion>9</LangVersion>
1111
</PropertyGroup>

0 commit comments

Comments
 (0)