GithubHelp home page GithubHelp logo

Comments (2)

ENikS avatar ENikS commented on July 28, 2024

Test rig:

            object tmp;
            var size = 10000000;
            var data = new string[size];
            for (var i = 0; i < size; i++)
                data[i] = i.ToString();
            
            Stopwatch timer = new Stopwatch();

            var dict = new Dictionary<string, string>();
            timer.Restart();
            foreach (var s in data)
            {
                dict[s] = s;
            }
            timer.Stop();
            var dictAdd = timer.ElapsedTicks.ToString("000,000");
            timer.Restart();
            foreach (var s in data)
            {
                tmp = dict[s];
            }
            timer.Stop();
            var dictGet = timer.ElapsedTicks.ToString("000,000");
            dict = null;
            GC.Collect();
            GC.WaitForFullGCComplete();

            var conc = new ConcurrentDictionary<string, string>();
            timer.Restart();
            foreach (var s in data)
            {
                conc[s] = s;
            }
            timer.Stop();
            var concAdd = timer.ElapsedTicks.ToString("000,000");
            timer.Restart();
            foreach (var s in data)
            {
                tmp = conc[s];
            }
            timer.Stop();
            var concGet = timer.ElapsedTicks.ToString("000,000");
            conc = null;
            GC.Collect();
            GC.WaitForFullGCComplete();

            var hash = new Hashtable();
            timer.Restart();
            foreach (var s in data)
            {
                hash[s] = s;
            }
            timer.Stop();
            var hashAdd = timer.ElapsedTicks.ToString("000,000");
            timer.Restart();
            foreach (var s in data)
            {
                tmp = hash[s];
            }
            timer.Stop();
            var hashGet = timer.ElapsedTicks.ToString("000,000");
            hash = null;
            GC.Collect();
            GC.WaitForFullGCComplete();

from container.

ENikS avatar ENikS commented on July 28, 2024

Number of samples is given in millions. Measurements are in Ticks.

Populating:

Implementation 1 5 10 15
Dictionary 338,422 1,946,961 4,136,670 X
Hashtable 582,512 6,013,090 X X
ConcurrtntDictionary 2,013,063 12,647,402 27,715,503 42,819,408

Reading from:

Implementation 1 5 10 15
Dictionary 174,306 1,087,306 2,326,253 X
Hashtable 311,539 1,422,119 X X
ConcurrtntDictionary 351,228 1,950,246 4,188,999 7,906,353

X - Means Out of Memory exception has been thrown.

from container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.