C++ can be slower than Python?

C++ can be slower than Python?

The Builder

1 год назад

75,726 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ItsCOMMANDer_
@ItsCOMMANDer_ - 07.01.2024 16:45

well written c/cpp code will always be faster than well written python code

Ответить
@VanStabHolme
@VanStabHolme - 03.01.2024 22:27

This was underwhelming

Ответить
@R00kTruth
@R00kTruth - 17.12.2023 20:53

my python runs much faster then the avg and im on old old gen.. but that is my secret ;-)

Ответить
@kapitan5888
@kapitan5888 - 17.12.2023 19:32

Use Reeccurrssiiooonnnnn :D

Ответить
@MoolsDogTwoOfficial
@MoolsDogTwoOfficial - 25.11.2023 12:33

Another thing you can do with strings is that instead of passing a const reference, it’d be better to use a string_view.

Ответить
@user-dz5pt3yr9z
@user-dz5pt3yr9z - 10.11.2023 23:32

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.

Ответить
@StevenRotelli
@StevenRotelli - 05.11.2023 22:42

Wow, so it was close, making a massive memory management mistake like that.

Ответить
@danial_amini
@danial_amini - 11.05.2023 15:49

very interesting. Is g++ faster or llvm (for this example)?

Ответить
@newuser132
@newuser132 - 22.12.2022 03:15

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!

Ответить
@williamdrum9899
@williamdrum9899 - 24.11.2022 07:52

I'm used to assembly so I use a pointer for anything bigger than the machine's register size out of habit.

Ответить
@petrjara7559
@petrjara7559 - 23.11.2022 02:58

Now make python to full copy the set 100 times

Ответить
@dinobotpwnz
@dinobotpwnz - 22.11.2022 00:12

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.

Ответить
@feschber
@feschber - 21.11.2022 11:27

How to make CPP slower than Python:
Write the most stupid code you possibly can

Ответить
@charliehe4542
@charliehe4542 - 21.11.2022 05:04

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.

Ответить
@TheTuubster
@TheTuubster - 20.11.2022 21:41

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.

Ответить
@ayoubelmhamdi7920
@ayoubelmhamdi7920 - 20.11.2022 16:01

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

Ответить
@iamgly
@iamgly - 20.11.2022 15:47

Also remember to add optimisations flag

Ответить
@tonik2558
@tonik2558 - 19.11.2022 19:23

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.

Ответить
@islamhamdane
@islamhamdane - 19.11.2022 18:15

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 .

Ответить
@ChronicoOne
@ChronicoOne - 19.11.2022 16:15

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🫠

Ответить
@VladykaVladykov
@VladykaVladykov - 19.11.2022 10:41

Для первого класса, либо для питонистов

Ответить
@__dark_channel__
@__dark_channel__ - 19.11.2022 00:17

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.

Ответить
@dbtalaviya
@dbtalaviya - 18.11.2022 15:54

Esi galti Kickstart mai kyu nahi dikhti

Ответить
@tashishsoni9011
@tashishsoni9011 - 18.11.2022 13:20

Dayum. That's alot of diff

Ответить
@danielhalachev4714
@danielhalachev4714 - 18.11.2022 09:57

Could you tell me about your vim configuration and plugins?

Ответить
@danielhalachev4714
@danielhalachev4714 - 18.11.2022 09:55

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.

Ответить
@brucea9871
@brucea9871 - 18.11.2022 05:24

That loud dinging sound your video made every time you pointed out a part of your program with a red arrow was very annoying.

Ответить
@vv1zard3x
@vv1zard3x - 18.11.2022 01:14

Omg....
You code:
get_first(vector<inc> c){...}

Must be:
get_first(const vector<int>& c) {...}

Default arguments in Python - references!))

Ответить
@432v01
@432v01 - 17.11.2022 22:52

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.

Ответить
@simongido565
@simongido565 - 17.11.2022 20:06

What is the point of this video?

Ответить
@alexengineering3754
@alexengineering3754 - 17.11.2022 16:28

A programmer that dosent know the difference between values and refferences dont deserve to Programm in c/c++

Ответить
@wgolyoko
@wgolyoko - 17.11.2022 15:50

If you're programming in C++ at all, you alrrady know what a reference is...

Ответить
@yusufklc7821
@yusufklc7821 - 17.11.2022 14:36

C++ is slower when you do not now anything yess

Ответить
@ukaosim
@ukaosim - 17.11.2022 13:28

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 🎉

Ответить
@protonray
@protonray - 17.11.2022 11:06

C++ is not for beginners

Ответить
@vrtex17
@vrtex17 - 17.11.2022 03:50

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++"

Ответить
@manofnorse
@manofnorse - 16.11.2022 22:31

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

Ответить
@dmytrokyrychuk7049
@dmytrokyrychuk7049 - 16.11.2022 20:58

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.

Ответить
@bloody1787
@bloody1787 - 16.11.2022 15:49

Lol, what kind of nonsense did I look at? The author is clearly not strong in C++

Ответить
@nullifiedvlad
@nullifiedvlad - 16.11.2022 13:27

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.

Ответить
@abludungeonmaster5817
@abludungeonmaster5817 - 16.11.2022 07:34

Yea. Pass by reference vs pointers vs new object is a rookie mistake. Gotta understand your scope.

Ответить
@Thewe34
@Thewe34 - 15.11.2022 13:57

Python is not language it’s script of c language

Ответить
@esben181
@esben181 - 15.11.2022 12:59

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

Ответить
@carlgeorgbiermann2915
@carlgeorgbiermann2915 - 15.11.2022 10:42

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

Ответить
@liyuubds6098
@liyuubds6098 - 14.11.2022 18:08

Another stupid clickbait man
What is the point of using a compiled language when you disable all compiler optimizations?

Ответить
@anlcangulkaya6244
@anlcangulkaya6244 - 13.11.2022 19:59

if you don't know putting this& you are not a programmer

Ответить