[RankColumn]
public class EnumTest
{
[Params(Weapon.WeaponType.A)]
public Weapon.WeaponType weaponType;
[Benchmark]
public string Case1()
{
return weaponType.GetNameSwitch();
}
[Benchmark]
public string Case2()
{
return weaponType.GetNameArray();
}
[Benchmark]
public string Case3()
{
return weaponType.GetNameToString();
}
}
public static class Weapon
{
public enum WeaponType
{
A,
B,
C,
}
private static string[] weaponTypeArray = {
"A",
"B",
"C",
};
public static string GetNameSwitch(this WeaponType type)
{
switch (type)
{
case WeaponType.A: return "A";
case WeaponType.B: return "B";
case WeaponType.C: return "C";
}
throw new NotImplementedException();
}
public static string GetNameArray(this WeaponType type)
{
return weaponTypeArray[(int)type];
}
public static string GetNameToString(this WeaponType type)
{
return type.ToString();
}
}