Today a friend and I were reflecting through System.Math (courtesy of IronPython) and we noticed the BigMul method:
Math.BigMul(Int32, Int32) : Int64
Why have a method just for multiplication? It seems to be a trivial reason to add a method to the .NET framework. After all, multiplication with casting does the same thing:
(long)a * (long)b
Being optimistic, I suggested that perhaps Microsoft's BigMul is implementing a faster and more efficient multiplication algorithm. Maybe there is a clever way to multiply two 32 bit numbers without explicit casting to 64 bit. Naturally, I wrote a simple speed test.
static void Main(string[] args)
{ int a = 40993; int b = 69872; long c = 0;DateTime start;
TimeSpan length;
Console.WriteLine("Inline multiplication");start = DateTime.Now;
for (int i = 0; i < 1000000000; i++)
c = (long)a * (long)b;
length = DateTime.Now - start;
Console.WriteLine(c);
Console.WriteLine(length.ToString());
Console.WriteLine();
Console.WriteLine("Math.BigMul");start = DateTime.Now;
for (int i = 0; i < 1000000000; i++)
c = Math.BigMul(a, b);
length = DateTime.Now - start;
Console.WriteLine(c);
Console.WriteLine(length.ToString());
Console.WriteLine();
Console.Read();
}
The results were not encouraging.

