Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • VBNC in Mono.

    1 answers - 1300 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

    At 10:52 AM 13/09/2006 +0200, K P wrote:
    >>But what is the reason for changing some of the .ToString into DirectCast ?

    >
    >If you check for the exact data type (as you did in all the cases I modified
    >to DirectCast) either for value types of for reference types there is no use
    >to do tricky conversions because we know the type of the variable so a
    >DirectCast is the most efficient and most reasonable conversion because
    >after a T <valueIs <typea DirectCast(<value>, <type>) will succeed
    >for sure. So I only suggest to change CType to DirectCast in these contexts.

    In the case of an that is known to contain a String, a call to
    ToString() may perform better than a direct cast. A cast still needs to
    check the type, even though the code has already just done it with a T
    (I'd be very surprised if the JIT can detect that pattern and only do one
    check). Calling .ToString() will be a virtual call to "return this;". It'd
    be interesting to do a comparison, but my intuition is that .ToString()
    would be significantly faster in this case.
    Jonathan Gilbert
    Mono-list maillist - Mono-list (AT) lists (DOT) ximian.com
  • No.1 | | 1177 bytes | |

    Thu, 14 Sep 2006 17:22:34 +0200, Jonathan Gilbert
    <2a5gjx302 (AT) sneakemail (DOT) comwrote:

    In the case of an that is known to contain a String, a call to
    .ToString() may perform better than a direct cast. A cast still needs to
    check the type, even though the code has already just done it with a
    T
    (I'd be very surprised if the JIT can detect that pattern and only do one
    check). Calling .ToString() will be a virtual call to "return this;".
    It'd
    be interesting to do a comparison, but my intuition is that .ToString()
    would be significantly faster in this case.

    Just tried it, but I got inconclusive results (sometimes .ToString()
    performed better, sometimes DirectCast performed better). During the first
    test runs .ToString() did perform better (5-10% better), then suddenly
    DirectCast started performed better (5-20% better), so I don't really
    think there is any big difference. I tried running with and without
    debugger, DEBUG and RELEASE builds, and with and without integer checks
    on, and always got inconclusive results (only on MS, I don't know how Mono
    will perform).

    Rolf

Re: VBNC in Mono.


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

EMSDN.COM