As Stringer Bell mentioned there is DivRem
which is not optimized up to .NET 3.5.
On .NET 4.0 it uses NGen.
The results I got with Math.DivRem
(debug; release = ~11000ms)
11863
11820
11881
11859
11854
Results I got with MyDivRem
(debug; release = ~11000ms)
29177
29214
29472
29277
29196
Project targeted for x86.
Math.DivRem
Usage example
int mod1;
int div1 = Math.DivRem(4, 2, out mod1);
Method signatures
DivRem(Int32, Int32, Int32&) : Int32
DivRem(Int64, Int64, Int64&) : Int64
.NET 4.0 Code
[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 Reference