[Mono-bugs] [Bug 373269] Math.Min and Math.Max

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 29 13:22:14 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=373269

User spouliot at novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=373269#c1


Sebastien Pouliot <spouliot at novell.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
                 CC|                                                |spouliot at novell.com
           Severity|Normal                                          |Enhancement




--- Comment #1 from Sebastien Pouliot <spouliot at novell.com>  2008-03-29 11:22:13 MST ---
I liked the idea (there a similar idea for DivRem on the google group) so I
started something. Sadly I found out that, at least by default (which is what
most mono application use), mono does not give better performance when using
Math.Min|Max.

# using Math.Min|Max
poupou at pollux:~/src/bugzilla> mcs minmax.cs
poupou at pollux:~/src/bugzilla> time mono minmax.exe
11727587164160

real    0m23.916s
user    0m23.745s
sys     0m0.092s

# using manually inlined code 
poupou at pollux:~/src/bugzilla> mcs minmax.cs
poupou at pollux:~/src/bugzilla> time mono minmax.exe
11727587164160

real    0m16.622s
user    0m16.445s
sys     0m0.068s


Source code:

using System;

class Program {

        static void Main (string[] args)
        {
                long value = 0;
                for (int i = 0; i < Int16.MaxValue; i++) {
                        for (int j = Int16.MaxValue; j >= 0; j--) {
#if false
                                value += Math.Max (i, j);
                                value -= Math.Min (i, j);
#else
                                value += (i > j) ? i : j;
                                value -= (i < j) ? i : j;
#endif
                        }
                }
                Console.WriteLine (value);
        }
}

Another test (my original one), where the min/max code was inside a method (to
clamp a value) showed similar results.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list