私は、渡された例外をチェックしてbool値を返すメソッドを持っています。例外タイプのパフォーマンスを確認する
現在、私の実装では、しかし、より良いパフォーマンスワイズ辞書検索ではなく、いくつかのOR
文とis
チェックを使用することです。このよう
private bool ExceptionShouldNotify(Exception e)
{
return
e is FirstCustomException ||
e is SecondCustomException ||
e is ThirdCustomException ||
e is FourthCustomException ||
e is FifthCustomException ||
e is SixthCustomException ||
e is SeventhCustomException;
}
のですか?
このような何か:
private bool ExceptionShouldNotify(Exception e)
{
var dict = new Dictionary<String, int> {
{ "FirstCustomException", 1 },
{ "SecondCustomException", 1 },
{ "ThirdCustomException", 1 },
{ "FourthCustomException", 1 },
{ "FifthCustomException", 1 },
{ "SixthCustomException", 1 },
{ "SeventhCustomException", 1 }
};
return dict.ContainsKey(e.GetType().Name);
}
ベンチマークではこれについて何を教えてくれましたか? –
辞書の場合は、むしろ 'HashSet' –
として実装したいと思います。本当にあなたが失敗の経路にいるときのパフォーマンスについて心配していますか?あなたの顧客は、「よく、落ちましたが、それは本当に速かった」と言っていると思いますか? –