How would you make this switch statement as fast as possible?

后端 未结 21 2221
别那么骄傲
别那么骄傲 2021-01-30 04:17

2009-12-04 UPDATE: For profiling results on a number of the suggestions posted here, see below!


The Question

Consider the following very

21条回答
  •  自闭症患者
    2021-01-30 05:02

    Assuming every input will be a valid ActivCode, that you can change the enumeration values and highly coupled to the GetHashCode implementation:

    enum MarketDataExchange
    {
        NONE,
        NBBO = 371857150,
        AMEX = 372029405,
        BSE = 372029408,
        BATS = -1850320644,
        NSE = 372029407,
        CHX = -284236702,
        NYSE = 372029412,
        ARCA = -734575383,
        NASDAQ = 372029421,
        NASDAQ_ADF = -1137859911,
        CBOE = 372029419,
        PHLX = 372029430,
        DIRECTEDGE = 372029429
    }
    
    public static MarketDataExchange GetMarketDataExchange(string ActivCode)
    {
        if (ActivCode == null) return MarketDataExchange.NONE;
    
        return (MarketDataExchange)ActivCode.GetHashCode();
    }
    

提交回复
热议问题