Can cpp code run slower than python?

Pages: 12
set_intersection isnt working with unordered sets..is there some other function that i can use??
closed account (10X9216C)
map/set/unordered_map/unordered_set are quite bad names, with no information on the underlying structure/algorithms. By using the short name "map" or "set", it tells the programmer this is the default, general implementation that should be used in most cases.

You shouldn't be assuming anything, that is indeed a bad habit. Always read the documentation. I don't believe that was the intended meaning for those names. As a programmer you should know better than to assume that just cause the word is short does not mean it is the best possible implementation. I know Python is willing to break compatibility but C++ isn't. If a new better optimized structure of a set/map is discovered, Python too won't follow this made up rule of yours, at least until they create Python 4 (breaking compataiblity) and no one bothers switching for the next 20 years.

While in reality, in 90 out of 100 cases a hash map is better than a tree map, because you don't need ordering.

While in reality, in 80 out of 90 of those cases, the performance (of map) doesn't matter as it isn't the bottleneck of the program.

almost all books/courses used map/sets in the examples and hords of programmers got used to them. I can see, it is quite hard for C++ guys to unlearn them.

How is it hard to unlearn? They use exactly the same interface, you literally just add "unordered_" to the variable class name. This might be true for anyone that isn't in CS, people that learn one way and even if they are presented with a better, easier, more efficient way they still use the way they first learned as they don't really care or aren't bothered to learn or grow. This is not just limited to "C++ guys(/gals)", but humanity as a whole and every other profession.
Last edited on
Can zerotable and onetable be vectors instead of sets? Lines 99-104 suggest that they can.

Move line 94 outside the loop. There's no sense recreating the array each time.

For other optimizations, run it under a profiler and see where it's spending its time.
@rapidcoder

That may be true, but when compared with languages like Java, C++ is a sandbox.

While in reality, in 80 out of 90 of those cases, the performance doesn't matter as it isn't the bottleneck of the program


Assuming C++ is pretty much designed around being high-performance, such claim sounds contradictory.


While in reality, in 80 out of 90 of those cases, the performance doesn't matter as it isn't the bottleneck of the program...


At the time map/set was added to C++, hash sets and hash maps were very well known data structures and were already present in some other language standard libraries. C++ designers just made a poor choice, for a performance-oriented language.


How is it hard to unlearn?


I don't know. Just observed the fact. I've seen just too much code using map/set where unordered_ was much better. Maybe people are simply not aware of the existence of unordered containers?


This might be true for anyone that isn't in CS


If so, then this is true for *most* programmers. Most programmers don't have solid CS background.
Last edited on
hi people..do u have any suggestions for set_intersection for unordered sets??
1
2
3
4
5
6
7
template <typename Set>
void anyordered_set_intersection(Set &dst, const Set &a, const Set &b){
    dst.clear();
    for (const auto &i : a)
        if (b.find(i) != b.end())
            dst.insert(i);
}
Last edited on
closed account (10X9216C)
Assuming C++ is pretty much designed around being high-performance, such claim sounds contradictory.

You should know better than to follow the bandwagon. It's so fast it doesn't need efficient data structures ;).

At the time map/set was added to C++, hash sets and hash maps were very well known data structures and were already present in some other language standard libraries. C++ designers just made a poor choice, for a performance-oriented language.

So? That doesn't change the fact that your ideology has an inherent flaw, or do you support languages breaking compatibility for such a petty reason?

I don't know. Just observed the fact. I've seen just too much code using map/set where unordered_ was much better. Maybe people are simply not aware of the existence of unordered containers?

Sounds like bias to me, i see this behavior in human beings everywhere, not just in c++. If they are unaware of unordered_map then they are unware of hash maps all together. I remember you saying you are a professor, if that wasn't just a bunch of hot air, you are probably basing that off personal experience with students more often than not. Which tend to be oblivious to how little they actually know.

If so, then this is true for *most* programmers. Most programmers don't have solid CS background.

Indeed most programmers are in it for the job opportunities and not because they enjoy it and want to grow to become something better or for other reasons. I misspoke when i said CS, what i actually meant was people that have a genuine pleasure for programming and a respect for the knowledge they gain with it. Of course the education system is kind of bad, i've seen programmers without CS degrees (or any for that fact) that would put 90 out of 100 students of what universities pump out to shame. It's not something you do without having a desire to learn on your own.
You should know better than to follow the bandwagon. It's so fast it doesn't need efficient data structures ;).
Well, which is it?
in 80 out of 90 of those cases, the performance doesn't matter as it isn't the bottleneck of the program.
closed account (10X9216C)
italics

People need to stop taking sentences out of context. The meaning of both those quotes are meaningless without rabidcoder's quotes to give meaning to the pronouns.
Last edited on
Oh, OK. Now I get it. I read it like this:
You should know better than to follow the bandwagon.
People on the bandwagon: It's so fast it doesn't need efficient data structures!
;).
The italics actually makes it more confusing.
Last edited on
Topic archived. No new replies allowed.
Pages: 12