Комментарии:
well written c/cpp code will always be faster than well written python code
ОтветитьThis was underwhelming
Ответитьmy python runs much faster then the avg and im on old old gen.. but that is my secret ;-)
ОтветитьUse Reeccurrssiiooonnnnn :D
ОтветитьAnother thing you can do with strings is that instead of passing a const reference, it’d be better to use a string_view.
ОтветитьAnything is slower in crooked hands. Python's strength is that everything it uses is already implemented in C libraries. Python just forwards the calls. And if something is not there, you should get it implemented in a C library before you could go ahead.
ОтветитьWow, so it was close, making a massive memory management mistake like that.
Ответитьvery interesting. Is g++ faster or llvm (for this example)?
ОтветитьC++ being slower than Python is just a myth--in reality, they are both excellent programming languages that each have their own strengths and weaknesses. It is true that Python is generally considered more high-level than C++, so it might be easier to learn and use in certain cases, but when it comes to pure coding speed and potential, they are actually pretty close to each other. So if you're looking to be as efficient as possible in your coding, you would be well-served to learn both C++ and Python, learning each language's best practices and using them together to build more powerful and efficient applications!
ОтветитьI'm used to assembly so I use a pointer for anything bigger than the machine's register size out of habit.
ОтветитьNow make python to full copy the set 100 times
ОтветитьAnother reason why C is better than C++. Passing a type vs passing a pointer to that type don't just look different in the function prototype. They look different in the call as well so you get more of the benefits of static typing.
ОтветитьHow to make CPP slower than Python:
Write the most stupid code you possibly can
What's happening here isn't just copying. The call by value with std::vector ask the memory allocator to allocate memory on heap every time the function is invoked. And after each call, the cloned vector get dropped which involves a call to memory allocator to deallocate the memory. This process is much much slower than just copying megabytes of integers.
Heap memory usage is much more expensive in non-GC languages like C, C++ or Rust. The fundamental reason that these languages are considered "faster" than Python or Java is because they provide tools enabling you to be precise and frugal about heap memory usage. If you were to use the "heap pointer soup" approach, which is common in Java or Python, in these languages, you are not likely to get any performance benefits.
There are still two "mistakes" in this code:
1. Only make it a non-const call-by-reference, if it is clear the object is going to be changed by the receiver. If not, make it a const-reference, so the one calling it knows, his object will not be changed but its status is the same after the routine ran.
2. If the routine expects to run through a list of objects that could be as large as 10 million, use an iterator and not a vector, as the iterator allows to catch the resource WHILE someone walks through the amount of objects as the vector forces to catch the complete set before passing it to another routine.
the time is less than one second of tree experience, that need more intention to understand how it's different,
should the results be more clearly, so i think we should use 1 billions instead of 1 million
Also remember to add optimisations flag
ОтветитьI like writing Rust because the equivalent code would be a hard compiler error. You are passing ownership of the list to the function you call, so either pass it by reference, or explicitly call clone on it to call it in a loop.
Of course the compiler tells you what the error is, why it's an error and what you can do to fix the error. A friendly compiler can help you feel like a genius.
wow I'm rally injoy watching your videos can you gives a carrer shift for some one whow start learning c++ in 2022,It's really help for motivation .thank's and keep going .
ОтветитьKey takeaway: pass big data by reference so you don't have to copy it all every time it is used. Also, good to use compiler optimizations unless you think you're better at assembly than the compiler. I know I'm not🫠
ОтветитьДля первого класса, либо для питонистов
ОтветитьYes this is a very important thing to be aware of as a C++ programmer.
Me and a friend found out that if you are using a set (say set<int> st) you should use st.lower_bound(value) as opposed to std::lower_bound(st.begin(), st.end(), value). The latter is linear whereas the former is logarithmic. I'm guess it also applies to upper_bound as well.
Esi galti Kickstart mai kyu nahi dikhti
ОтветитьDayum. That's alot of diff
ОтветитьCould you tell me about your vim configuration and plugins?
ОтветитьLast year I studied Data Structures and Algorithms at university. We had homework every week, checked with automatic tests for speed. That's when I learned this practice by myself. Making copies not only slows down the operations, it uses memory inefficiently. Thank you for reminding be about this, I haven't coded in C++ for several months.
ОтветитьThat loud dinging sound your video made every time you pointed out a part of your program with a red arrow was very annoying.
ОтветитьOmg....
You code:
get_first(vector<inc> c){...}
Must be:
get_first(const vector<int>& c) {...}
Default arguments in Python - references!))
As one started programming with C++, I still prefer the C++ setting: value is value and reference is reference. The consistency makes me feel good.
ОтветитьWhat is the point of this video?
ОтветитьA programmer that dosent know the difference between values and refferences dont deserve to Programm in c/c++
ОтветитьIf you're programming in C++ at all, you alrrady know what a reference is...
ОтветитьC++ is slower when you do not now anything yess
ОтветитьThe reason that’s the case is that python passes arguments by reference 😅… when the same technique (pass by reference) is used in c++ it’s even faster 🎉
ОтветитьC++ is not for beginners
ОтветитьImmediately when he showed a function that takes in a collection i was like "you silly goof, you're gonna pass out by value in c++"
ОтветитьIgnorant Python programmers! C++ release programs must be compiled with -O3 or -O4, and then the C++ result is
> time ./a.out
real 0m00.00s
user 0m00.00s
sys 0m00.00s
I am a python developer, and I know very little about C++, but I would assume that the majority of C++ developers are aware of what a reference is, and are concious about which variables are passed by reference, and which are passed by value.
ОтветитьLol, what kind of nonsense did I look at? The author is clearly not strong in C++
ОтветитьDid you noticed that in python you pass a REFERENCE to list so you don't copy it, and you also forgot about compiler optimization flags.Well your "test" doesn't make any sense.
ОтветитьYea. Pass by reference vs pointers vs new object is a rookie mistake. Gotta understand your scope.
ОтветитьPython is not language it’s script of c language
ОтветитьIt wouldnt surprise me because you're copying the entire array instead of passing a reference to it which is probably what Python does by default
ОтветитьJust last friday, I was puzzled over the bad performance of my code, where I dealt with objects tens of megabytes large. It was exactly that: missed a & in the argument list of a function. I was really glad it was nothing more serious than that :D
ОтветитьAnother stupid clickbait man
What is the point of using a compiled language when you disable all compiler optimizations?
if you don't know putting this& you are not a programmer
Ответить