Exemple #1
0
    public static SymbolC Intern(string name)
    {
        SymbolC value;
        var     hash = name.GetHashCode();

        if (internedSymbols.TryGetValue(hash, out value))
        {
            return(value);
        }
        else
        {
            value = new SymbolC(name, internedSymbolsList.Count);
            internedSymbols[hash] = value;
            return(value);
        }
    }
Exemple #2
0
    private void Start()
    {
        var quantity = 1000000;

        UnityEngine.Debug.Log("INTERN STRING");
        var s = string.Empty;

        TestBegin();
        for (var i = 0; i < quantity; i++)
        {
            s = string.Intern(i.ToString());
        }
        UnityEngine.Debug.LogFormat("[String.Intern] duration: {0}", TestEnd());


        Symbol sym = null;

        TestBegin();
        for (var i = 0; i < quantity; i++)
        {
            sym = Symbol.Intern(i.ToString());
        }
        UnityEngine.Debug.LogFormat("[Symbol.FromName] duration: {0}", TestEnd());

        SymbolA syma = null;

        TestBegin();
        for (var i = 0; i < quantity; i++)
        {
            syma = SymbolA.Intern(i.ToString());
        }
        UnityEngine.Debug.LogFormat("[SymbolA.FromName] duration: {0}", TestEnd());

        SymbolB symb = null;

        TestBegin();
        for (var i = 0; i < quantity; i++)
        {
            symb = SymbolB.Intern(i.ToString());
        }
        UnityEngine.Debug.LogFormat("[SymbolB.FromName] duration: {0}", TestEnd());

        SymbolC symc = null;

        TestBegin();
        for (var i = 0; i < quantity; i++)
        {
            symc = SymbolC.Intern(i.ToString());
        }
        UnityEngine.Debug.LogFormat("[SymbolC.FromName] duration: {0}", TestEnd());


        UnityEngine.Debug.Log("COMPARISONG TEST");

        TestBegin();
        var s1 = string.Intern("QWERTYUIOP{{{{SDFGHJKL");

        for (var i = 0; i < quantity; i++)
        {
            var b = s == s1;
        }
        UnityEngine.Debug.LogFormat("[String.Intern comparison] duration: {0}", TestEnd());

        TestBegin();
        var sym1 = Symbol.Intern("QWERTYUIOP{{{{SDFGHJKL");

        for (var i = 0; i < quantity; i++)
        {
            var b = sym == sym1;
        }
        UnityEngine.Debug.LogFormat("[Symbol.FromName comparison] duration: {0}", TestEnd());

        TestBegin();
        var syma1 = SymbolA.Intern("QWERTYUIOP{{{{SDFGHJKL");

        for (var i = 0; i < quantity; i++)
        {
            var b = syma == syma1;
        }
        UnityEngine.Debug.LogFormat("[SymbolA.FromName comparison] duration: {0}", TestEnd());


        TestBegin();
        var symb1 = SymbolB.Intern("QWERTYUIOP{{{{SDFGHJKL");

        for (var i = 0; i < quantity; i++)
        {
            var b = symb.hash == symb1.hash;
        }
        UnityEngine.Debug.LogFormat("[SymbolB.FromName comparison] duration: {0}", TestEnd());


        TestBegin();
        var symc1 = SymbolC.Intern("QWERTYUIOP{{{{SDFGHJKL");

        for (var i = 0; i < quantity; i++)
        {
            var b = symc.id == symc1.id;
        }
        UnityEngine.Debug.LogFormat("[SymbolC.FromName comparison] duration: {0}", TestEnd());
    }