Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:39:24+00:00 2026-06-04T20:39:24+00:00

I’m programming an apartment & house rental site. Since there are never more than

  • 0

I’m programming an apartment & house rental site. Since there are never more than 10’000 properties for rent, it’s no problem to load em all into memory. Now, when a users want to search for a specific one, he can define very much filters for price, room, escalator etc.

Every property has a very different set of attributes. One property may have an attribute that another property does not have. So, creating a Class in C# that has all the attributes, while only a few of them are used is not a good idea to me. I decided to use a Dictionary instead.

A few benchmarks later, I found out, that the Dictionary is about 40 times slower in accessing attributes as a Class. I also did a benchmark for node.js, which just used objects as dictionarys. This was absolutely interesting because the exact same program in node.js performed even better than the C# example with a native class.

In fact I got the following results:

C# Dictionary: ~820ms
C# Class: ~26ms
Node.js Object: ~24ms

Each benchmark searched 1’000’000 objects by the same criterias.

I know that the Node.js version is that fast because of the V8 engine by Google. Do you know if there is a C# class that uses similar techniques as the V8 engine and gets almost the same performance?

C# Dictionary Benchmark

namespace Test {
    class Program {
        static void Main(string[] args) {

            PropertyList p = new PropertyList();
            long startTime = DateTime.Now.Ticks;
            for (int i = 0; i < 100; i++) {
                p.Search();
            }
            Console.WriteLine((DateTime.Now.Ticks - startTime) / 10000);
        }
    }

    class PropertyList {
        List<Property> properties = new List<Property>();
        public PropertyList() {
            for (int i = 0; i < 10000; i++) {
                Property p = new Property();
                p["Strasse"] = "Oberdorfstrasse";
                p["StrassenNr"] = 6;
                p["Plz"] = 6277;
                p["Ort"] = "Lieli";
                p["Preis"] = 600;
                p["Fläche"] = 70;
                p["Zimmer"] = 2;
                p["Lift"] = true;
                p["Verfügbarkeit"] = 7;
                p["Keller"] = false;
                p["Neubau"] = true;
                p["ÖV"] = false;

                properties.Add(p);
            }
        }
        public void Search() {
            int found = 0;

            for (int i = 0; i < properties.Count; i++) {
                Property p = properties[i];
                if ((string)p["Strasse"] == "Oberdorfstrasse" &&
                   (int)p["StrassenNr"] == 6 &&
                   (int)p["Plz"] == 6277 &&
                   (string)p["Ort"] == "Lieli" &&
                   (int)p["Preis"] >= 500 && (int)p["Preis"] <= 1000 &&
                   (int)p["Fläche"] >= 10 && (int)p["Fläche"] <= 200 &&
                   (int)p["Zimmer"] == 2 &&
                   (bool)p["Lift"] == true &&
                   (int)p["Verfügbarkeit"] >= 2 && (int)p["Verfügbarkeit"] <= 8 &&
                   (bool)p["Keller"] == false &&
                   (bool)p["Neubau"] == true &&
                   (bool)p["ÖV"] == true
                ) {
                    found++;
                }
            }
        }
    }

    class Property {
        private Dictionary<string, object> values = new Dictionary<string, object>();

        public object this[string key] {
            get {
                return values[key];
            }
            set {
                values[key] = value;
            }
        }
    }
}

C# Class Benchmark

namespace Test {
    class Program {
        static void Main(string[] args) {

            SpecificPropertyList p2 = new SpecificPropertyList();

            long startTime2 = DateTime.Now.Ticks;
            for (int i = 0; i < 100; i++) {
                p2.Search();
            }

            Console.WriteLine((DateTime.Now.Ticks - startTime2) / 10000);

        }
    }

    class SpecificPropertyList {
        List<SpecificProperty> properties = new List<SpecificProperty>();
        public SpecificPropertyList() {
            for (int i = 0; i < 10000; i++) {
                SpecificProperty p = new SpecificProperty();
                p.Strasse = "Oberdorfstrasse";
                p.StrassenNr = 6;
                p.Plz = 6277;
                p.Ort = "Lieli";
                p.Preis = 600;
                p.Fläche = 70;
                p.Zimmer = 2;
                p.Lift = true;
                p.Verfügbarkeit = 7;
                p.Keller = false;
                p.Neubau = true;
                p.ÖV = false;

                properties.Add(p);
            }
        }
        public void Search() {
            int found = 0;

            for (int i = 0; i < properties.Count; i++) {
                SpecificProperty p = properties[i];
                if (p.Strasse == "Oberdorfstrasse" &&
                   p.StrassenNr == 6 &&
                   p.Plz == 6277 &&
                   p.Ort == "Lieli" &&
                   p.Preis >= 500 && p.Preis <= 1000 &&
                   p.Fläche >= 10 && p.Fläche <= 200 &&
                   p.Zimmer == 2 &&
                   p.Lift == true &&
                   p.Verfügbarkeit >= 2 && p.Verfügbarkeit <= 8 &&
                   p.Keller == false &&
                   p.Neubau == true &&
                   p.ÖV == true
                ) {
                    found++;
                }
            }
        }
    }

    class SpecificProperty {
        public string Strasse;
        public int StrassenNr;
        public int Plz;
        public string Ort;
        public int Preis;
        public int Fläche;
        public int Zimmer;
        public bool Lift;
        public int Verfügbarkeit;
        public bool Keller;
        public bool Neubau;
        public bool ÖV;
    }
}

Node.js Benchmark

var properties = [];

for(var i = 0; i < 10000; i++){
    var p = {
        Strasse:"Oberdorfstrasse",
        StrassenNr:6,
        Plz:6277,
        Ort:"Lieli",
        Preis:600,
        Fläche:70,
        Zimmer:2,
        Lift:true,
        Verfügbarkeit:7,
        Keller:false,
        Neubau:true,
        ÖV:false
    };
    properties.push(p);
}



function search(){
    var found = 0;
    for(var i = 0; i < properties.length; i++){
        var p = properties[i];
        if(p.Strasse == "Oberdorfstrasse" && p.StrassenNr == 6 && p.Plz == 6277 && p.Ort == "Lieli" &&
            p.Preis >= 500 && p.Preis <= 1000 &&
            p.Fläche>= 10 && p.Fläche <= 100 &&
            p.Zimmer == 2 &&
            p.Verfügbarkeit >= 2 && p.Verfügbarkeit <= 8 &&
            p.Keller == false && p.Neubau == true && p.ÖV == false
        ){
            found++;
        }
    }
}
var startTime = new Date().getTime();
for(var i = 0; i < 100; i++){
    search();
}
console.log(new Date().getTime()-startTime);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:39:26+00:00Added an answer on June 4, 2026 at 8:39 pm

    Ok, the reason for C# being slower is that V8 is optimized for exactly this scenario (lots of dictionaries having exactly the same members).

    You are kind of misusing C# here. Instead of a dictionary, just use a normal class with auto-properties. C# will be much faster then, even faster than V8 (because you are playing to its strength and not to its weakness).

    And that is why your “specific object” benchmark is the fastest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.