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

ByteHelpers.ToHex: Use .NET implementation #12101

Merged

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Dec 18, 2023

Simple https://benchmarkdotnet.org benchmark confirms that we no longer need the custom code:

[MemoryDiagnoser]
public class Benchmarks
{
	private byte[] _bytes;

	[Params(4, 16, 128)]
	public int Length { get; set; }

	[GlobalSetup]
	public void Setup() => _bytes = RandomNumberGenerator.GetBytes(Length);


	[Benchmark]
	public string Master()
	{
		return WalletWasabi.Helpers.ByteHelpers.ToHex(_bytes);
	}

	[Benchmark]
	public string Pr()
	{
		return Convert.ToHexString(_bytes);
	}
}

Results:

Method Length Mean Error StdDev Median Gen 0 Gen 1 Allocated
Master 4 11.18 ns 0.314 ns 0.911 ns 10.91 ns 0.0063 - 40 B
Pr 4 12.01 ns 0.271 ns 0.628 ns 11.98 ns 0.0064 - 40 B
Master 16 18.84 ns 0.398 ns 0.332 ns 18.91 ns 0.0140 - 88 B
Pr 16 16.43 ns 0.361 ns 0.632 ns 16.26 ns 0.0140 - 88 B
Master 128 101.23 ns 1.651 ns 2.027 ns 100.90 ns 0.0854 0.0001 536 B
Pr 128 55.80 ns 1.124 ns 2.056 ns 55.38 ns 0.0854 0.0002 536 B

@kiminuo kiminuo marked this pull request as ready for review December 19, 2023 12:59
@lontivero lontivero merged commit e571458 into WalletWasabi:master Dec 20, 2023
7 checks passed
@kiminuo kiminuo deleted the feature/2023-12-18-Use-NET-ToHexString branch December 20, 2023 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants