Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Generic Array.Sort

    5 answers - 254 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hey,
    I've attached a patch containing the impl for the generic versions of
    Array.Sort.
    Could anybody take a look at it?
    Carlos.
    Mono-devel-list mailing list
    Mono-devel-list (AT) lists (DOT) ximian.com
  • No.1 | | 563 bytes | |

    Hey,

    I've attached a patch containing the impl for the generic versions of
    Array.Sort.

    1) all the combsort stuff can probably go, IMH -- With generics, we will
    be able to inline stuff (it will take a bit of jit optimization though --
    we basically need to do inlining).

    2) qsort <Tis unused

    3) compare<Tshould be removed. You should use Comparer <T>.Default. I
    specially coded this class to be fast.
    -- Ben

    Mono-devel-list mailing list
    Mono-devel-list (AT) lists (DOT) ximian.com
  • No.2 | | 1146 bytes | |

    Hello,

    Comments below:

    El vie, 19-08-2005 a las 01:08 -0400, Ben Maurer :
    Hey,

    I've attached a patch containing the impl for the generic versions of
    Array.Sort.

    1) all the combsort stuff can probably go, IMH -- With generics, we will
    be able to inline stuff (it will take a bit of jit optimization though --
    we basically need to do inlining).

    Currently we use combsort with simple types, which doesn't need to use
    the CompareTo methods, since they have associated runtime instructions,
    as far as I know.

    Second, if inlining could help us in this scenario, can it do it right
    now? If that's not the case, we could keep these combsort methods and
    remove them when we are ready.

    2) qsort <Tis unused

    It's used for the Comparison<Tsort version

    3) compare<Tshould be removed. You should use Comparer <T>.Default. I
    specially coded this class to be fast.

    , let's keep it using Comparer<T>.Default

    Carlos.

    Mono-devel-list mailing list
    Mono-devel-list (AT) lists (DOT) ximian.com
  • No.3 | | 1520 bytes | |

    El vie, 19-08-2005 a las 01:08 -0400, Ben Maurer :
    >Hey,
    >>

    >I've attached a patch containing the impl for the generic versions
    >of Array.Sort.
    >>

    >1) all the combsort stuff can probably go, IMH -- With generics, we
    >will be able to inline stuff (it will take a bit of jit optimization
    >though -- we basically need to do inlining).
    >

    Currently we use combsort with simple types, which doesn't need to use
    the CompareTo methods, since they have associated runtime instructions,
    as far as I know.

    Second, if inlining could help us in this scenario, can it do it right
    now? If that's not the case, we could keep these combsort methods and
    remove them when we are ready.

    No, we can't. Also, to make this work we'd need to have a version of the
    function with Comparer<T>.Default explicitly taken in the method (so that
    we could inline there). However, the difference between the combsort and
    the normal code path should be much smaller with generics. Feel free to do
    a benchmark.

    If we really wanted performance, we could do an icall here. The libc qsort
    is hyper-optimized. IMH, there is no way we could compete, especially for
    large arrays. Feel free to benchmark and prove me wrong though.
    -- Ben

    Mono-devel-list mailing list
    Mono-devel-list (AT) lists (DOT) ximian.com
  • No.4 | | 1331 bytes | |

    08/19/05 Ben Maurer wrote:
    If we really wanted performance, we could do an icall here. The libc qsort
    is hyper-optimized. IMH, there is no way we could compete, especially for
    large arrays. Feel free to benchmark and prove me wrong though.

    What if, for a change, _you_ write a benchmark and get some data before
    making a claim?

    Hint: qsort does a call for each compare.
    Hint2: qsort likely does a memcpy() or a switch on size on each swap.
    Hint3: qsort doesn't support a custom swap callback as is needed in the
    API.
    Hint4: if a compare method is provided, handing it over to libc's qsort
    means doing an unmanaged->managed transition for each compare, ouch.
    Hint5: often the arrays sizes to compare are small and the transition
    costs dominate the performance if you use an icall.

    As a data point, for int[] sorts, the current combsort code is faster
    than a pure C program that calls qsort (so avoiding a lot of overhead) up
    to 100 K elements, sometimes by as much as 2 times faster. It is just as
    fast up to more than 300 K elements if jit optimizations are enabled
    (=all).
    But, hey, the perl script I used to generate the random numbers
    for testing may have generated the right optimial sequence for the
    combosrt used in corlib.

    lupus
  • No.5 | | 758 bytes | |

    Hello,

    yes, it has a good performance. But we have a problem, because the
    runtime has a problem comparing generic types. See:

    After this is solved, we can apply the patch.

    Carlos.

    El lun, 05-09-2005 a las 11:27 -0400, Ben Maurer :
    Hey,

    Thu, 2005-08-18 at 20:45 -0500, Carlos Alberto Cortez wrote:
    I've attached a patch containing the impl for the generic versions of
    Array.Sort.

    What's the status of this patch? I am thinking that the performance of
    this is probably good enough that we can get it in. IIRC, there were no
    comments other than my performance based ones on the list.
    -- Ben

    Mono-devel-list mailing list
    Mono-devel-list (AT) lists (DOT) ximian.com

Re: Generic Array.Sort


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "Development"

EMSDN.COM