-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customizing CultureInfo, fix #1295
- Loading branch information
1 parent
05df0eb
commit e6a248b
Showing
59 changed files
with
302 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Globalization; | ||
using System.Threading; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
|
||
namespace BenchmarkDotNet.Samples | ||
{ | ||
[Config(typeof(Config))] | ||
[ShortRunJob] | ||
public class IntroCultureInfo | ||
{ | ||
private class Config : ManualConfig | ||
{ | ||
public Config() | ||
{ | ||
var cultureInfo = (CultureInfo) CultureInfo.InvariantCulture.Clone(); | ||
cultureInfo.NumberFormat.NumberDecimalSeparator = "@"; | ||
FormatStyle = new FormatStyle(cultureInfo); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Foo() => Thread.Sleep(100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace BenchmarkDotNet.Configs | ||
{ | ||
public class FormatStyle : IEquatable<FormatStyle> | ||
{ | ||
public static readonly CultureInfo DefaultCultureInfo; | ||
public static readonly Encoding DefaultEncoding = Encoding.ASCII; | ||
public static readonly FormatStyle DefaultStyle; | ||
|
||
public CultureInfo CultureInfo { get; } | ||
public Encoding Encoding { get; } | ||
|
||
static FormatStyle() | ||
{ | ||
DefaultCultureInfo = (CultureInfo) CultureInfo.InvariantCulture.Clone(); | ||
DefaultCultureInfo.NumberFormat.NumberDecimalSeparator = "."; | ||
DefaultStyle = new FormatStyle(DefaultCultureInfo, DefaultEncoding); | ||
} | ||
|
||
public FormatStyle(CultureInfo cultureInfo, Encoding encoding) | ||
{ | ||
CultureInfo = cultureInfo; | ||
Encoding = encoding; | ||
} | ||
|
||
public FormatStyle(CultureInfo cultureInfo) : this(cultureInfo, DefaultEncoding) { } | ||
|
||
public FormatStyle(Encoding encoding) : this(DefaultCultureInfo, encoding) { } | ||
|
||
public bool Equals(FormatStyle other) => Equals(CultureInfo, other.CultureInfo) && Equals(Encoding, other.Encoding); | ||
|
||
public override bool Equals(object obj) => obj is FormatStyle other && Equals(other); | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return ((CultureInfo != null ? CultureInfo.GetHashCode() : 0) * 397) ^ (Encoding != null ? Encoding.GetHashCode() : 0); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.