Multiplication is faster than bit shifting
This commit is contained in:
parent
b6627af65f
commit
593107e190
|
@ -81,7 +81,7 @@ namespace MediaBrowser.Common
|
||||||
break; // Unreachable
|
break; // Unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes[j] = (byte)((a << 4) | b);
|
bytes[j] = (byte)((a * 16) | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Jellyfin.Common.Benches
|
||||||
[MemoryDiagnoser]
|
[MemoryDiagnoser]
|
||||||
public class HexDecodeBenches
|
public class HexDecodeBenches
|
||||||
{
|
{
|
||||||
[Params(0, 10, 100, 1000, 10000, 1000000)]
|
[Params(/*0,*/ 10, 100, 1000, 10000, 1000000)]
|
||||||
public int N { get; set; }
|
public int N { get; set; }
|
||||||
|
|
||||||
private string data;
|
private string data;
|
||||||
|
@ -40,6 +40,9 @@ namespace Jellyfin.Common.Benches
|
||||||
public byte[] Decode() => Hex.Decode(data);
|
public byte[] Decode() => Hex.Decode(data);
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
|
public byte[] Decode2() => Hex.Decode2(data);
|
||||||
|
|
||||||
|
//[Benchmark]
|
||||||
public byte[] DecodeSubString() => DecodeSubString(data);
|
public byte[] DecodeSubString() => DecodeSubString(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Jellyfin.Common.Benches
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
//_ = BenchmarkRunner.Run<HexEncodeBenches>();
|
||||||
_ = BenchmarkRunner.Run<HexDecodeBenches>();
|
_ = BenchmarkRunner.Run<HexDecodeBenches>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user