ストリンガーベルが述べたように、.NET3.5まで最適化されていないDivRem
ものがあります。
.NET 4.0では、NGenを使用します。
私が得た結果Math.DivRem
(デバッグ;リリース=〜11000ms)
11863
11820
11881
11859
11854
私が得た結果MyDivRem
(デバッグ;リリース=〜11000ms)
29177
29214
29472
29277
29196
x86を対象としたプロジェクト。
Math.DivRem
使用例
int mod1;
int div1 = Math.DivRem(4, 2, out mod1);
メソッドシグネチャ
DivRem(Int32, Int32, Int32&) : Int32
DivRem(Int64, Int64, Int64&) : Int64
.NET4.0コード
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static int DivRem(int a, int b, out int result)
{
result = a % b;
return (a / b);
}
.NET 4.0 IL
.custom instance void System.Runtime.TargetedPatchingOptOutAttribute::.ctor(string) = { string('Performance critical to inline across NGen image boundaries') }
.maxstack 8
L_0000: ldarg.2
L_0001: ldarg.0
L_0002: ldarg.1
L_0003: rem
L_0004: stind.i4
L_0005: ldarg.0
L_0006: ldarg.1
L_0007: div
L_0008: ret
MSDNリファレンス