C++ can be slower than Python?

  Рет қаралды 75,561

The Builder

The Builder

Жыл бұрын

This C++ program is MUCH slower compared to Python because of this programming Mistake
Speed comparison between a Python program and a C++ program.
==== Awesome Links ====
🗣 Discord: / discord
✍️ Github: github.com/TheBuilder-software
💎 Patreon: / topshelftechnology

Пікірлер: 203
@cipherxen2
@cipherxen2 Жыл бұрын
It's still impressive that it copied about 4GB of memory in 2 seconds
@xClairy
@xClairy Жыл бұрын
69 likes Noice imma ruin it
@parlor3115
@parlor3115 Жыл бұрын
I doubt that's what happened
@themakabrapl2248
@themakabrapl2248 Жыл бұрын
I think he is not wrong, it copied 3,7252902984619 GB of data in 2s. But I could be wrong myself I haven't made a vector with a certain size i c++ so i don't know if this is appropriate way to achive that but if it is he is not wrong
@RRKS_TF
@RRKS_TF Жыл бұрын
@@parlor3115 I am very certain that I'd did infact copy the entire vector for each call as no optimisation flags were provided meaning the assembly is functionally identical to the C++ code with no shortcuts being taken
@jvstbecause
@jvstbecause Жыл бұрын
@@parlor3115 1 Construction + 100 Copy Constructions = 101 Reservations 101 Reservations * 10.000.000 Elements * 4 (sizeof int) / (1024 * 1024) ~= 3853 Mebibyte of Data that must be reserved. That makes almost 4 Gebibyte
@ohwow2074
@ohwow2074 Жыл бұрын
And let's not forget that you didn't specify any optimizations for C++ compiler. C++ without -O2 is actually very inefficient and garbage. The whole purpose of compiled languages is the aggressive optimization possibilities.
@Vili69420
@Vili69420 Жыл бұрын
i was about to point that out as well
@kyrneh7629
@kyrneh7629 Жыл бұрын
If you compile it with optimization, even the first c++ code runs in exactly 0 time (at least with clang). The generated assembly is just one no-op, because the compiler realized that the whole program does nothing at all. The real takeaway of this example should thus be: "Use compiler optimizations!" Of cause "Always pass by const reference!" is also good advice to every beginner c++ programmer.
@ohwow2074
@ohwow2074 Жыл бұрын
@@kyrneh7629 you can add a volatile keyword so that the compiler doesn't optimize that away. Also pass by reference is not the most efficient way for all data types. For objects that are the size of the machine word size (e.g. 8 bytes for 64 bit architectures) pass by value is simply more efficient. And for huge things like containers you either move them or pass them by reference.
@idanyel1587
@idanyel1587 Жыл бұрын
Come on, man, if you add the -O2 will look ahead and it will know that the function calls are not used, so they will be eliminated. Don't mess up things if you don't know the behavior.
@maxaafbackname5562
@maxaafbackname5562 Жыл бұрын
I think that even for simple data types like integers it does not harm to pass by _const_ reference with an optimizing compiler. The reference is optimized away.into a pass by value.
@gengarboi8745
@gengarboi8745 Жыл бұрын
Yeah in my computer science class the importance of references was one of the first things we learned the moment we started working with std::strings and std::vectors. It may seem like a reason to argue that C++ has a higher learning curve but, at least on the surface, it seems roughly similar to Rust's borrowing system.
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
Don't confuse rusts strict borrowing rules with the sloppy c++ refrences. Rust is memory safe c++ is not.
@gengarboi8745
@gengarboi8745 Жыл бұрын
@@redcrafterlppa303 I don't see how they're any different in just this scenario. You don’t want to copy the whole object so you just "borrow" or "reference" it.
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
@@gengarboi8745.. And this is where the similarities end. Also where c++ refrences end. They are simply "the same" as some other variable. Rusts borrowing rules ensure valid objects in time and space. C++ has no concept of temporal bounds and limited control over spacial bounds. Rust has no null or nullptr every variable is bound to valid memory. This is what makes rust great and c++ frustrating.
@jakubskop73
@jakubskop73 Жыл бұрын
@@redcrafterlppa303 C++ has fewer limitations in that respect - which is good or bad depending on your expertise
@gengarboi8745
@gengarboi8745 Жыл бұрын
@@redcrafterlppa303 OK well thank you for going on this massive tangent that was unrelated to my point that I don't care about. You're really doing God's work for Rust here.
@dmytrokyrychuk7049
@dmytrokyrychuk7049 Жыл бұрын
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.
@stijndcl
@stijndcl Жыл бұрын
And if not, using a proper linter/IDE will tell you to pass by reference if you aren't. CLion for example automatically refactors this for you as well.
@brinza888
@brinza888 Жыл бұрын
Well, there are no auto decisions about passing by value or reference in C++ (at the end of video u can see way to fix problem and enforce compiler to pass by reference). It is responsibility of programmer, that's why it is so important. And that is why the trouble shown may appear in your code.
@dimi144
@dimi144 5 ай бұрын
In C++, everything is passed by value unless you specify otherwise. I also thought that C++ developers knew what a reference was, but since videos like these are so common maybe I was wrong for thinking that
@azmah1999
@azmah1999 4 ай бұрын
@@dimi144 Nah, this type of video are common because they're trivial to make and the possible audience of people starting to learn how to code is bigger than the one of people knowing how to code
@TheBuilder
@TheBuilder 4 ай бұрын
We are on KZbin
@pharoah327
@pharoah327 Жыл бұрын
As soon as you showed the C++ code, I was shouting to make it a ref (actually it should be a const ref since you aren't changing it). Any competent C++ developer should know this.
@v01d_r34l1ty
@v01d_r34l1ty Жыл бұрын
I prefer pointers
@pharoah327
@pharoah327 Жыл бұрын
@@v01d_r34l1ty that's fine too. For this case, I think the difference would be minimal and wouldn't have an effect.
@TheBuilder
@TheBuilder Жыл бұрын
If you look closely my linter suggested making the vector const which is why the variable changed colour
@pharoah327
@pharoah327 Жыл бұрын
@@TheBuilder I didn't catch that. I love static analyzers.
@dimi144
@dimi144 5 ай бұрын
​@@v01d_r34l1ty where you can use a reference instead of a pointer, you should, this is C++, not C
@rterminatu
@rterminatu Жыл бұрын
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 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.
@carlgeorgbiermann2915
@carlgeorgbiermann2915 Жыл бұрын
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
@sparky173j
@sparky173j Жыл бұрын
It's funny how much you have to do to make it slower than python. A billion int transfers is a lot!
@SunPodder
@SunPodder Жыл бұрын
Even by passing without reference took me 0.018s. Just use compiler optimizations :)
@PKua007
@PKua007 Жыл бұрын
In this case the whole loop will be optimized out, because it does nothing, unless you for example print the result. In the end all that that code will do is allocate the memory, memset it to 0, free it and return.
@alexandrubossro
@alexandrubossro Жыл бұрын
That's actually a very good and useful tutorial! Thanks 🙏
@TheTuubster
@TheTuubster Жыл бұрын
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.
@TheBuilder
@TheBuilder Жыл бұрын
You're right but this is above the skill level I'm targeting for this video
@TheA-rl4zo
@TheA-rl4zo Жыл бұрын
Could you elaborate on the second point, thank you
@nuelzemudio883
@nuelzemudio883 Жыл бұрын
@@TheA-rl4zo Every collection type has a dedicated iterator for traversing its collection. It is best to use the iterator to access the elements in the collection than trying to do it manually using a loop. Take for example a string. A string is just an array/collection of char objects. But the proper way to traverse a string is using string_view.
@danial_amini
@danial_amini Жыл бұрын
@@nuelzemudio883 would it be too much to ask for your version of the c++ code? I still don't get it lol sorry (I'm a noob). So the 10 million vector is an inefficient container? Are you suggesting something else like arrays?
@ukaosim
@ukaosim Жыл бұрын
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 🎉
@__aot__
@__aot__ Жыл бұрын
Exactly. C++ always wins.
@MoolsDogTwoOfficial
@MoolsDogTwoOfficial 7 ай бұрын
Another thing you can do with strings is that instead of passing a const reference, it’d be better to use a string_view.
@TheBuilder
@TheBuilder 7 ай бұрын
yes if you plan on doing operations on that view later, passing either works
@danial_amini
@danial_amini Жыл бұрын
very interesting. Is g++ faster or llvm (for this example)?
@TheBuilder
@TheBuilder Жыл бұрын
i doubt there would be a difference
@kevincole2843
@kevincole2843 Жыл бұрын
important and often overlooked.
@misaalanshori
@misaalanshori Жыл бұрын
Yeah i haven't done this before, but that is definitely a mistake I would've made.
@TheBypasser
@TheBypasser 2 ай бұрын
Wonder what happens should we get rid of that std_vector and go for a calloc()/free() instead...
@islamhamdane
@islamhamdane Жыл бұрын
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 .
@misobarisic4013
@misobarisic4013 Жыл бұрын
At least specify an optimisation level for c++
@TheBuilder
@TheBuilder Жыл бұрын
I want the compiler to show you my mistakes not hide them
@tonik2558
@tonik2558 Жыл бұрын
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.
@TheBuilder
@TheBuilder Жыл бұрын
I have to agree, argument passing is one place C++ has artificial complexity. I think there is a new language being proposed cppfront that tries to redesign away some of the bad default behaviour
@vrtex17
@vrtex17 Жыл бұрын
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++"
@vrtex17
@vrtex17 Жыл бұрын
I was meant to write "pass it by reference" but I'm not correcting it.
@StevenRotelli
@StevenRotelli 7 ай бұрын
Wow, so it was close, making a massive memory management mistake like that.
@williamdrum9899
@williamdrum9899 Жыл бұрын
I'm used to assembly so I use a pointer for anything bigger than the machine's register size out of habit.
@griffinschreiber6867
@griffinschreiber6867 4 ай бұрын
I wrote an entire neural network WITHOUT USING THIS OPTIMIZATION!?????? I'm so glad I watched this video.
@esben181
@esben181 Жыл бұрын
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
@awabkhan2977
@awabkhan2977 Жыл бұрын
Good video.
@TheBuilder
@TheBuilder Жыл бұрын
Glad you enjoyed it
@JokeryEU
@JokeryEU Жыл бұрын
but you havent showed us the result AFTER the & was applied :(
@TheBuilder
@TheBuilder Жыл бұрын
It may not be clear but when I run the two command at the end of the video, they print out the timings
@432v01
@432v01 Жыл бұрын
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.
@kelali
@kelali Жыл бұрын
0:33 no because you are copying the vector every get_first call
@vv1zard3x
@vv1zard3x Жыл бұрын
Omg.... You code: get_first(vector c){...} Must be: get_first(const vector& c) {...} Default arguments in Python - references!))
@InconspicuousChap
@InconspicuousChap 7 ай бұрын
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.
@TheBuilder
@TheBuilder 7 ай бұрын
correct, which makes python in the truest sense a scripting language like bash
@InconspicuousChap
@InconspicuousChap 7 ай бұрын
@@TheBuilderit is one. It's designed for non-programmers: data scientists, sysadmins, etc. I once tried to implement a Python's math's factorial algorithm in Python itself. Got an awfully slow deficient implementation, even slower than brute force multiplication of numbers. This language is just a thin layer upon C libraries.
@EgnachHelton
@EgnachHelton Жыл бұрын
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.
@xeridea
@xeridea 5 ай бұрын
I would agree, except, the reason Python is slow, is that it is an interpreted language, which in in of itself makes it about 20x slower. All that flexibility and ease of use comes at a cost.
@wgolyoko
@wgolyoko Жыл бұрын
If you're programming in C++ at all, you alrrady know what a reference is...
@6754bettkitty
@6754bettkitty 5 ай бұрын
0:21 PASS BY REFERENCE! 😱
@adrianprayoga335
@adrianprayoga335 Жыл бұрын
I won't take "Umm, actually you can use pointer for that" as a joke ever again
@dbtalaviya
@dbtalaviya Жыл бұрын
Esi galti Kickstart mai kyu nahi dikhti
@idanyel1587
@idanyel1587 Жыл бұрын
Try to use the same thing, but add .copy() to the python list, it will be even worse The fact that c++ handles that pretty well is amazing, python is trash.
@TheBuilder
@TheBuilder Жыл бұрын
Don't be so harsh with Python, its still better than Bash in my book
@g.4279
@g.4279 Жыл бұрын
Performance isn't very important for most applications honestly.
@idanyel1587
@idanyel1587 Жыл бұрын
@Mala Suerte, I can play the same game with you: try to develop an operating system using python. Your point is useless.
@idanyel1587
@idanyel1587 Жыл бұрын
@@g.4279, right, right. Just for your knowledge, the python interpreter is written in C, data base engines are written is C / C++, mostly alll applications rely on a software written in C / C++ and you come here to say the performance isn't important, interesting.
@g.4279
@g.4279 Жыл бұрын
​@@idanyel1587 I know what Python is written in and I never said performance is *never* important. But for the majority of modern computing it isn't. The majority of software out there aren't programming languages or operating systems. Developer time is far more valuable than a few more milliseconds in most cases. Which is why you see C++ in certain industries and Python is others.
@petrjara7559
@petrjara7559 Жыл бұрын
Now make python to full copy the set 100 times
@TheBuilder
@TheBuilder Жыл бұрын
just let python have this one ☺
@abludungeonmaster5817
@abludungeonmaster5817 Жыл бұрын
Yea. Pass by reference vs pointers vs new object is a rookie mistake. Gotta understand your scope.
@zipur3364
@zipur3364 Жыл бұрын
So how does python solve this issue? Automatic pointers?
@sledgex9
@sledgex9 Жыл бұрын
IIRC python's collections don't make deep copies when assigned to another variable or passed as a parameter. The new variable/parameter just points to the same object as the initial variable.
@taragnor
@taragnor Жыл бұрын
Basically. It's the same way most high level languages do. There's no hidden copies. Unless you use .copy() or .clone() or whatever, you'll pass the original object. I find the hidden copies that C++ can do sometimes to be really tricky. Rust solves this problem by having move by default and no non-explicit copies.
@sledgex9
@sledgex9 Жыл бұрын
@@taragnor Personally I find the reverse true. When I assign a variable to "something" I expect it to make a copy of the data. When I mutate that "something" via the new variable I don't expect it to have sideffects on the original variable too.
@taragnor
@taragnor Жыл бұрын
​@@sledgex9 I mean, working with any language other than C/C++, if you take any kind of object and say a=b, the idea is that a isn't a copy of b, but rather a and b are the same object. When you want to copy something, it's an explicit action. This is important because copies can be shallow or deep, so it's a good idea to always specify when a copy is happening and what kind of copy it is. Not to mention if you've got copies of large objects going on, that can be a serious performance drag, so it's generally not a good idea to have implicit copies, except for very small data structures, like primitives, tuples of primitives, etc. With a language as focused on performance as C++ is, having it set up where you can so easily make performance crushing copies is just not very good design. The thing about C++ is that sometimes you don't get punished for this, because the compiler is pretty smart in that it will do move elision if it can to save you the copy, but in cases like this video, where it can't, it just quietly makes thousands of copies and you may be none the wiser. In Rusts case, doing a double reference to the same object would break its ownership model, so it instead has an assignment perform a move. While this can be unintuitive, the nice thing is that the compiler will warn you when you're using a variable that's already been moved, so in practice it will never actually cause you any problems. Since Rust tracks all that ownership stuff, you'll never get a case where you corrupt an existing object you still want. Basically what happens is that either you never use the original variable again, and Rust just ignores it. Or you try to use it again and get a compiler error. And the Rust method still gives you the fine control over memory that C++ would, where you know what's on the stack and what's on the heap.
@sledgex9
@sledgex9 Жыл бұрын
@@taragnor I don't know man. To me, it is far more intuitive that an assignment equals copy. To me, an assignment basically says "hey, I want my variable to have this value". If I want a mutation on my new variable to affect another variable I prefer to be explicit about that(value assigned by reference/pointer). But since this a matter of preference, there's no point in arguing about this.
@ayoubelmhamdi7920
@ayoubelmhamdi7920 Жыл бұрын
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
@birtantaskn7762
@birtantaskn7762 3 ай бұрын
This is not actually a mistake; one can identify it as a mistake if they are unfamiliar with pointers.
@tashishsoni9011
@tashishsoni9011 Жыл бұрын
Dayum. That's alot of diff
@iamgly
@iamgly Жыл бұрын
Also remember to add optimisations flag
@brucea9871
@brucea9871 Жыл бұрын
That loud dinging sound your video made every time you pointed out a part of your program with a red arrow was very annoying.
@stephenhowe4107
@stephenhowe4107 Жыл бұрын
Yes, worked this out at 0:25
@QuickTechNow
@QuickTechNow 24 күн бұрын
Lets not forget that Python runs ontop of C++. And "-O3" would help too. Ill never understand how python scripters can call themselves programmer / code too.
@vedqiibyol
@vedqiibyol Жыл бұрын
Or just don't use the standard library......
@TheBuilder
@TheBuilder Жыл бұрын
I can't live without my vectors
@surv5k
@surv5k Жыл бұрын
@@TheBuilder vectors are life
@ItsCOMMANDer_
@ItsCOMMANDer_ 5 ай бұрын
well written c/cpp code will always be faster than well written python code
@VladykaVladykov
@VladykaVladykov Жыл бұрын
Для первого класса, либо для питонистов
@yeeter269
@yeeter269 Жыл бұрын
Nice
@mochou-p
@mochou-p Жыл бұрын
and use an array if you care about speed
@IchiganCS
@IchiganCS Жыл бұрын
Aren't const ref vectors just more elaborate arrays? I think accessing a vector and accessing an array is actually the same operation, isn't it?
@TheBuilder
@TheBuilder Жыл бұрын
​@@IchiganCS The underlying data of a vector is just an array. If your vector never changes size you won't notice a difference in speed. You might consider using std:array in the case you know your array will never change size
@newuser132
@newuser132 Жыл бұрын
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!
@TheBuilder
@TheBuilder Жыл бұрын
Idk, the forced indents in python and lack of low level logic structures like for loops makes python hard to use for educational purposes like writing sorts for example
@xeridea
@xeridea 5 ай бұрын
Anyone claiming Python can be as fast as C++ is delirious.
@xeridea
@xeridea 5 ай бұрын
@@TheBuilder Another person who hates forced indents! I have intentionally not learned Python much in part for this reason. If I need to quickly write something where speed isn't important, I use PHP.
@sparant1
@sparant1 Жыл бұрын
Watch how KZbinr obtains basic knowledge how computers work (pass by reference vs pass by value - always know which ur language is doing)
@TheBuilder
@TheBuilder Жыл бұрын
Glad you enjoyed it :)
@simongido565
@simongido565 Жыл бұрын
What is the point of this video?
@TheBuilder
@TheBuilder Жыл бұрын
yes
@feschber
@feschber Жыл бұрын
How to make CPP slower than Python: Write the most stupid code you possibly can
@TheBuilder
@TheBuilder Жыл бұрын
Its not that hard to write sloppy code in C++
@Awwe12675
@Awwe12675 Жыл бұрын
Python is not language it’s script of c language
@anlcangulkaya6244
@anlcangulkaya6244 Жыл бұрын
if you don't know putting this& you are not a programmer
@alexengineering3754
@alexengineering3754 Жыл бұрын
A programmer that dosent know the difference between values and refferences dont deserve to Programm in c/c++
@weirddan455
@weirddan455 3 ай бұрын
Yes, C++ is slower than Python if you make run 10 million miles further (pass by value) after shooting it in the knee (compiled with optimizations disabled).
@TheBuilder
@TheBuilder 3 ай бұрын
Yes
@GooogleGoglee
@GooogleGoglee Жыл бұрын
In JAVA?
@GooogleGoglee
@GooogleGoglee Жыл бұрын
@patrick w r u? & Y?
@gengarboi8745
@gengarboi8745 Жыл бұрын
Java and C# use references in a different way. It tries to handle memory management on its own and use references automatically for large objects passed to functions. You have to use the "new" keyword to explicitly create new objects.
@sayven
@sayven Жыл бұрын
@@GooogleGoglee Primitives (i.e. those data types that start with a lower case letter, int, char, boolean...) always get copied. Non-primitives are always passed by reference (unless you specifically create a new object with a copy constructor or do something similar)
@GooogleGoglee
@GooogleGoglee Жыл бұрын
❤ JAVA
@b-penajohneric151
@b-penajohneric151 2 ай бұрын
I referencing the exact code to Java (I'm using ArrayList as basis of flexible array), the compiler took 0 seconds (maybe milliseconds) to build and run so yeah there's no need to pass down the reference as c++ does unless one of your data types is in primitive state.
@R00kTruth
@R00kTruth 6 ай бұрын
my python runs much faster then the avg and im on old old gen.. but that is my secret ;-)
@yusufklc7821
@yusufklc7821 Жыл бұрын
C++ is slower when you do not now anything yess
@TheBuilder
@TheBuilder Жыл бұрын
I've seen newbies write exponential growth functions to calculate linear time problem like finding if a value exists in an array
@dinobotpwnz
@dinobotpwnz Жыл бұрын
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.
@xeridea
@xeridea 5 ай бұрын
Both languages have their strengths. I wouldn't say either is better than the other. In C, it is much easier to have memory leaks, due to the lack of smart pointers, and being forced to manually implement many things that C++ gives you for free. C++ isn't great for kernels, drivers, or low power embedded systems though.
@_Admin
@_Admin Жыл бұрын
bruh
@bloody1787
@bloody1787 Жыл бұрын
Lol, what kind of nonsense did I look at? The author is clearly not strong in C++
@TheBuilder
@TheBuilder Жыл бұрын
why is that
@n00blamer
@n00blamer Жыл бұрын
Someone missed the title of the video.. :_D
@VanStabHolme
@VanStabHolme 5 ай бұрын
This was underwhelming
@protonray
@protonray Жыл бұрын
C++ is not for beginners
@TheBuilder
@TheBuilder Жыл бұрын
first language i learned in school was C
@protonray
@protonray Жыл бұрын
@@TheBuilder As a rule of thumb for c++ beginners: pass integral values per value and everything else per const ref. If const ref will not fit for a certain case - then you have to adapt it with care.
@n00blamer
@n00blamer Жыл бұрын
@@protonray System V AMD64 ABI is pretty neat.. Integer/Pointer Arguments 1-6 RDI, RSI, RDX, RCX, R8, R9 Floating Point Arguments 1-8 XMM0 - XMM7 Excess Arguments Stack If you pass float or double as reference, you take performance hit. If you pass __mm128* by reference, you get hit again. The MS 64 bit ABI is a bit less stellar but same general rules of thumb apply.
@protonray
@protonray Жыл бұрын
@@n00blamer maybe it was confusing, with integral values I mean (bool, u/ints, floats/doubles) and aliases on them.
@ragilmalik
@ragilmalik Жыл бұрын
Pypy is actually much muuuuch faster than cpython. Still like thrice slower than c but 100x faster than cpython.
@pattappat
@pattappat Жыл бұрын
hello c++ users - I am the average python user. this is definitely not a mistake, it will make your code faster. yes definitely. this is not an attempt to sabotage the c++ community and become one rank higher in speed than before, no no most certainly not. please carry on making this mistake- I mean discovery.
@ChronicoOne
@ChronicoOne Жыл бұрын
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🫠
@manofnorse
@manofnorse Жыл бұрын
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
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,7 МЛН
The Fastest Way to Loop in Python - An Unfortunate Truth
8:06
mCoding
Рет қаралды 1,4 МЛН
small vs big hoop #tiktok
00:12
Анастасия Тарасова
Рет қаралды 10 МЛН
DELETE TOXICITY = 5 LEGENDARY STARR DROPS!
02:20
Brawl Stars
Рет қаралды 22 МЛН
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 95 МЛН
the cleanest feature in C that you've probably never heard of
8:13
Low Level Learning
Рет қаралды 127 М.
Compiled Python is FAST
12:57
Doug Mercer
Рет қаралды 98 М.
1 YEAR OF PYTHON CODING IN 1 MINUTE !!!!!
1:02
Pythonic
Рет қаралды 15 М.
Best Order to Learn Algorithms & Data Structures
1:00
NeetCodeIO
Рет қаралды 121 М.
Comparing C to Assembly
10:50
The Builder
Рет қаралды 6 М.
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 791 М.
Most Popular Programming Languages 1965 - 2022
6:47
Data Is Beautiful
Рет қаралды 1,5 МЛН
сюрприз
1:00
Capex0
Рет қаралды 1,5 МЛН
MacBook Air Японский Прикол!
0:42
Sergey Delaisy
Рет қаралды 573 М.
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 24 МЛН
Секретный смартфон Apple без камеры для работы на АЭС
0:22
One To Three USB Convert
0:42
Edit Zone 1.8M views
Рет қаралды 441 М.