Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Last active December 20, 2016 00:00
Show Gist options
  • Save mattwarren/d2be775eec5a7adba928 to your computer and use it in GitHub Desktop.
Save mattwarren/d2be775eec5a7adba928 to your computer and use it in GitHub Desktop.
Benchmark of C# 6 String Interpolation vs calling ToString() directly
// Inspired by https://twitter.com/Nick_Craver/status/702693060472414208
public class Framework_Interpolated_vs_ToString
{
	private long counter = 0;

	[Setup]
	public void Setup()
	{
		counter = 0;
	}

	[Benchmark]
	public new string ToString()
	{
		return counter.ToString() + " ms";
	}

	[Benchmark]
	public string InterpolatedString()
	{
		return $"{counter} ms";
	}
}
@gitfool
Copy link

gitfool commented Dec 16, 2016

How does it scale with the number of interpolated parameters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment