With the -Ox compilation option enabled in C++, the code would execute instantly (close to zero) since the compiler would recognize that the variable "sum" is never accessed and has no side effects. Consequently, your code would simply become "int main() {//nothing here}". If your code did access "sum," for example, by printing it out using "cout
You should also mention that other implementations are faster then others, some like PyPy which has a just in time compiler option can optimize code a crazy amount.
This test wasnt fair for Java and Go. Go had the build included in the time when it could have just been running the binary, and Java was not compiled to a .class file so of course it would be much slower in interpreted mode.
Yea I don't understand that. The whole point is to get subscribers right? 😂 Communicating effectively with comments gets you subs. He needs to watch tutorials on YouTubing effectively
Who cares? This dude arguably has among the best python videos on the internet. This dude could easily combing cash in at a FANG job but instead provides these videos to us.
@@sadf1416 yea I understand that but usually when you do tutorials, you should at least see if anyone has problems. That's the whole point of teaching.
It is true that python is slower at execution, but to have high performance, it is often recommended to use built-in functions (programmed in C) like sum in this case. With sum(range(100000000)), the speed will be increased.
Why are you not compiling the Java code via "javac Main.java" first and after that invoking the interpreter with "java Main"? By simply using "java Main.java" you are actually measuring compile time for generating the byte code plus execution time (you don't do that for your C code).
@@nocopyrightgameplaystockvi231 you could use GraalVM native image to also compile to native code. Generally I think benchmarking such low code makes no sence. it give you only a hint of trivial functions. To really do benchmarking you have to go through multiple different processing areas (compute, memory management, IO etc.) and also let all of them run longer times. Else you can hit a "sweet spot" in one of the languages. Also if you compare pre-compiled, runtime languages and just in time compiled you need to at least run them all longer to avoid differences in startup time.
@@dr.rainereschrich1549 agreed. Although for me compilation never mattered at all, unless you are running something incredibly intensive like over 2M appends to a list, which I once tested myself using Python's List, Numpy arrays and Array types. Guess who was the winner. I actually like more of Data structure based speed tests where Python falls behind most languages unless you start substituting with Cython.
On my computer I get similar results for the python and C matrix time measurements. If I use -O3 to compile the C program it is 4 times faster than the python version
You mistakenly ran "time node.main.js" instead of "time node main.js". The speed for JS was wrong. Also, Python generates bytecodes. You need to rerun the code to measure the real speed.
IMHO, a few things need clarification: - The java times include compilation time, unlike C. Also, java gets faster when executing a function more than once, possibly faster than C. Also, javascript gets faster. - Like numpy, BLAS libraries can also be used with C or Java. - The python syntax is more beginner-friendly but bites back in large projects. Like lack of encapsulation etc. Otherwise, good video with some valid points.
@@nocopyrightgameplaystockvi231 My java timings, compared to NeuralNine's java command =100%) are: - 24.5% (javac; time java) - 11.6% (10 iterations to give the hotjava compiler a chance, 10.4% after 100 iterations - C does not get faster when executed repeatedly) As the C version in NeuralNine's test looks like being 2x as fast as Java (or is it 4x?), the true performance is the same for C and Java, if not Java is faster. My original Java timing (w/o javac, 1 iteration) is: real 0m0.299s user 0m0.306s sys 0m0.037s which is faster than C. This is in line with the common understanding that compiled java and C are about equally fast.
@@falklumo It does. But the end product of Javac isn't binaries as GCC does. Its a class file which has to be processed again by the interpreter for creating MC and then you can see the output.
@@nocopyrightgameplaystockvi231 Actually, javac compiles to a binary just like gcc does. The difference is that the binary code is for a virtual processor, not an X86 or ARM. (Sun Microsystems actually built actual hardware processors once upon a time ;) ) But there should be little to no performance difference for long enough an execution. The technology isn't too different from what Apple does for the M1 with X86 binaries actually. You wouldn't say X86 code on the M1 is interpreted because it is blazingly fast and actually converted into ARM code on the fly ...
I'm all for Python as a quick devel tool but your comparison to C, unfortunately, is not fair and is even somewhat misleading. At around 14:38 you should change the order of loop nesting from i, j, k to i, k, j and only then report the time. How much faster is it now?
interesting but did you take into consideration that it may be different process times with bigger programs.? Also, optimization largely depends on how the code is written. optimization is basically the least amount of readable code in a program, as I understand it.
"Optimization is the least amount of readable code in a program" - what? Are you talking about optimizing developement speed? Because otherwise this makes no sense
I just want to add a few things. If you use PyPy intead of CPython for the code in this video, you'll find that it's actually faster than the C program. But if you used a more optimized algorithm for each of these programs, the C is much faster. The C code would be much faster if you write it like this #include int main() { long long N = 100000000; long long sum = (N * (N - 1)) / 2; printf("Sum: %lld ", sum); return 0; }
hmm... The last variant is unfair, since you use an external library to do the multiplication. You can do that in (nearly) every other language also and then the other language is also faster in developing/coding.
Faster than assembly language! And at the expense of python and the simplicity of the code. This can also be done in assembler, and the code will be just as simple. You just need to write a macro that implements such a function, it will take some time, but then everything will be as simple as on Python.
This is the code for UASM! ;; v0.0 .686 .xmm .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc includelib \masm32\lib\kernel32.lib include msvcrt.inc include macros.asm .code main proc local time:sdword, tmp:sdword, i:sdword, j:sdword local A:dword, B:dword, R:dword mov time, clock() ASSUME esi:ptr real8, edi:ptr real8, ebx:ptr real8 mov A, GlobalAlloc(GPTR, 500*500*8) mov B, GlobalAlloc(GPTR, 500*500*8) mov R, GlobalAlloc(GPTR, 500*500*8) mov esi, A mov edi, B mov ebx, R .for (eax=0, i=eax: i
It turned out to speed up the code, after all, the assembler is faster than Python, even if some particularly magical libraries are used in this python of yours. mov ebx, R .for (eax=0: eax
I understand your points. However, this is Python's fault. My opinion is Python should give us to choose of assigning static variables and compile the code. The default settings may be dynamic data types and interpreter, I have no problem with that, but that is the exact reason of why Python is slow. As a user I would like to have an option to write code like C but in Python syntax (if I need speed), If I do not, then I could write code as the default Python settings. But that should be my choice. for example, age is an integer value, the interpreter should not "have to" check in every single time. (By the way it is has to be a positive integer value between (0, 127), if I write that in C, I defined it as char age; So, more optimizations can be made) I have no idea about why they do not let us define any static value, static data type and compile my code (Interpreter great while developing but after final product developed, I prefer a compiled program. Like. const PI = 3.14 int age = 20
The first task wasn't run for javascript, it failed and you only assessed the time it took to fail. Also, java should be compiled first for a real measurement
Is this guy an amateur pretending to be a professional? Either that or he's trying really hard to "sell" python. I see no other justification for such a terrible video. First and foremost, he doesnt write any "warmup" code that would allow some languages to have lower times on the benchmarks. He could then compare that to the version without said "warmup" code and see how large the difference is or isnt. Secondly, he does one run and thats it. No averages whatsoever. And to make matters worst, he's measuring compile times, for example, for java. Ridiculous honestly. He's also not using any optimizations for C which is just as ridiculous. Finally, I like how he tries to "sell" python at the end by comparing a version using a library to versions of Java and C without library. Yeah, python development speed is faster, but if you use Java and C libraries you can make those languages almost as fast development wise. Like c'mon man, at least put some effort into it. Edit: he also complete ignores different implementations of interpreters and compilers for each language which can produce very different results. What a joke of a video
Only mean to criticise constructively dude, your methodology is severely flawed. You are measuring the compile times along with the execution times. You should be compiling binaries and measuring execution speed of those.
First of all, end-to-end measurement you are doing is completely incorrect. You should've done it inside of your scripts. Second, with python it is REALY hard to work on complex projects, since there is no type system (the one python has is a joke), hence the development speed would slow down dramatically as the project grows. Not hating on python, I think it is a great language for small projects and scripting.
You can create a virtual type system using MyPy. Google and Facebook even developed their own versions of it. It's not going to make execution any faster but it helps a lot in terms of development and working on complex projects.
With the -Ox compilation option enabled in C++, the code would execute instantly (close to zero) since the compiler would recognize that the variable "sum" is never accessed and has no side effects. Consequently, your code would simply become "int main() {//nothing here}". If your code did access "sum," for example, by printing it out using "cout
Gold comment
For the first test, you can apply a simple formula: sum = (n * n + n)/2 while taking into account the condition i
Geeks, bruv
You should also mention that other implementations are faster then others, some like PyPy which has a just in time compiler option can optimize code a crazy amount.
PP lmao
This test wasnt fair for Java and Go. Go had the build included in the time when it could have just been running the binary, and Java was not compiled to a .class file so of course it would be much slower in interpreted mode.
i swear this guy never checks comments and is literally never online in his discord at all. its like he makes a video then goes to narnia
Yea I don't understand that. The whole point is to get subscribers right? 😂
Communicating effectively with comments gets you subs.
He needs to watch tutorials on YouTubing effectively
He is probably on the grind when he goes off camera
Who cares? This dude arguably has among the best python videos on the internet. This dude could easily combing cash in at a FANG job but instead provides these videos to us.
@@sadf1416 yea I understand that but usually when you do tutorials, you should at least see if anyone has problems. That's the whole point of teaching.
@@sadf1416 no he couldn’t
It is true that python is slower at execution, but to have high performance, it is often recommended to use built-in functions (programmed in C) like sum in this case. With sum(range(100000000)), the speed will be increased.
I just tried this on Colab and this simple change actually makes the code run 7x faster. It went from taking 15.061 seconds to only 2.147 seconds.
So just use c
To sum a range you can use a formula with O(1) i think it is (n² + n) / 2
You should've done go build and then execute the binary produced. That would've been faster
the node js loop benchmark one errored, we didn't get the real result
Why are you not compiling the Java code via "javac Main.java" first and after that invoking the interpreter with "java Main"? By simply using "java Main.java" you are actually measuring compile time for generating the byte code plus execution time (you don't do that for your C code).
Because C compiles to binaries directly. Java is Code to class then to binary.
@@nocopyrightgameplaystockvi231 you could use GraalVM native image to also compile to native code.
Generally I think benchmarking such low code makes no sence. it give you only a hint of trivial functions. To really do benchmarking you have to go through multiple different processing areas (compute, memory management, IO etc.) and also let all of them run longer times. Else you can hit a "sweet spot" in one of the languages. Also if you compare pre-compiled, runtime languages and just in time compiled you need to at least run them all longer to avoid differences in startup time.
Bcz he suck he didnt compile go either lol
@@dr.rainereschrich1549 agreed. Although for me compilation never mattered at all, unless you are running something incredibly intensive like over 2M appends to a list, which I once tested myself using Python's List, Numpy arrays and Array types. Guess who was the winner. I actually like more of Data structure based speed tests where Python falls behind most languages unless you start substituting with Cython.
because the guy who posts videos on this channel has no idea what he is doing
Javascript code was not executed actually. Because you've typed time node.main.js ...and got 'Command not found' error.
On my computer I get similar results for the python and C matrix time measurements. If I use -O3 to compile the C program it is 4 times faster than the python version
Would be interesting to see how fast it is with Python 3.11.
3.12 its out with 60% more speed
@@electra2707_ Python 3.11 is 60% faster than 3.10. Python 3.12 is not out yet
I hope you also talk about Cython, CPython, and other extensions for speed comparison.
Very nice video, thank you, and this operator you publish before as the most unknown is really awesome.
You mistakenly ran "time node.main.js" instead of "time node main.js". The speed for JS was wrong. Also, Python generates bytecodes. You need to rerun the code to measure the real speed.
3.11 is faster than previous python versions.
IMHO, a few things need clarification:
- The java times include compilation time, unlike C. Also, java gets faster when executing a function more than once, possibly faster than C. Also, javascript gets faster.
- Like numpy, BLAS libraries can also be used with C or Java.
- The python syntax is more beginner-friendly but bites back in large projects. Like lack of encapsulation etc.
Otherwise, good video with some valid points.
I don't think you can actually write java bytecode directly
@@nocopyrightgameplaystockvi231 javac compiles java, just like gcc compiles C.
@@nocopyrightgameplaystockvi231 My java timings, compared to NeuralNine's java command =100%) are:
- 24.5% (javac; time java)
- 11.6% (10 iterations to give the hotjava compiler a chance, 10.4% after 100 iterations - C does not get faster when executed repeatedly)
As the C version in NeuralNine's test looks like being 2x as fast as Java (or is it 4x?), the true performance is the same for C and Java, if not Java is faster.
My original Java timing (w/o javac, 1 iteration) is:
real 0m0.299s
user 0m0.306s
sys 0m0.037s
which is faster than C. This is in line with the common understanding that compiled java and C are about equally fast.
@@falklumo It does. But the end product of Javac isn't binaries as GCC does. Its a class file which has to be processed again by the interpreter for creating MC and then you can see the output.
@@nocopyrightgameplaystockvi231 Actually, javac compiles to a binary just like gcc does. The difference is that the binary code is for a virtual processor, not an X86 or ARM. (Sun Microsystems actually built actual hardware processors once upon a time ;) ) But there should be little to no performance difference for long enough an execution. The technology isn't too different from what Apple does for the M1 with X86 binaries actually. You wouldn't say X86 code on the M1 is interpreted because it is blazingly fast and actually converted into ARM code on the fly ...
add a `-O3` while compiling c code and see the results
How did you customize the windows and Linux terminals with the background images?
There will be one more player in this game. Mojo. Could you make some video about it (with benchmarking)?
I'm all for Python as a quick devel tool but your comparison to C, unfortunately, is not fair and is even somewhat misleading. At around 14:38 you should change the order of loop nesting from i, j, k to i, k, j and only then report the time. How much faster is it now?
wow, thanks for sharing knowledge, subscibed.
Completely disagree with the development speed comment. That should be an entirely new metric of productivity. Calling it speed just confuses.
interesting but did you take into consideration that it may be different process times with bigger programs.? Also, optimization largely depends on how the code is written. optimization is basically the least amount of readable code in a program, as I understand it.
"Optimization is the least amount of readable code in a program" - what? Are you talking about optimizing developement speed? Because otherwise this makes no sense
@@lengors7327 yes development speed.
I just want to add a few things. If you use PyPy intead of CPython for the code in this video, you'll find that it's actually faster than the C program. But if you used a more optimized algorithm for each of these programs, the C is much faster. The C code would be much faster if you write it like this
#include
int main() {
long long N = 100000000;
long long sum = (N * (N - 1)) / 2;
printf("Sum: %lld
", sum);
return 0;
}
hmm... The last variant is unfair, since you use an external library to do the multiplication. You can do that in (nearly) every other language also and then the other language is also faster in developing/coding.
Why don’t you use numpy for python?
I think you forgot to recompile the updated go script.
Why did it take so long to not find a command in bash ("node." instead of "node ")
You should have used hyperfine to benchmark all these
Bixly interests me thank you
Faster than assembly language! And at the expense of python and the simplicity of the code. This can also be done in assembler, and the code will be just as simple. You just need to write a macro that implements such a function, it will take some time, but then everything will be as simple as on Python.
In assembler, I replaced the FPU code with SSE2, and this added speed, it was 460 msec, it became 314 msec.
This is the code for UASM!
;; v0.0
.686
.xmm
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include msvcrt.inc
include macros.asm
.code
main proc
local time:sdword, tmp:sdword, i:sdword, j:sdword
local A:dword, B:dword, R:dword
mov time, clock()
ASSUME esi:ptr real8, edi:ptr real8, ebx:ptr real8
mov A, GlobalAlloc(GPTR, 500*500*8)
mov B, GlobalAlloc(GPTR, 500*500*8)
mov R, GlobalAlloc(GPTR, 500*500*8)
mov esi, A
mov edi, B
mov ebx, R
.for (eax=0, i=eax: i
It turned out to speed up the code, after all, the assembler is faster than Python, even if some particularly magical libraries are used in this python of yours.
mov ebx, R
.for (eax=0: eax
Would you consider local pricing on your books in the future?
Why is it that you aren’t initializing the C array in the python using numpy like you are for the Java and the c?
in c , you are use double instead of int or uint16
It wasn’t necessary to use the includes in the C programs.
is the @ in python really using that "k" loop too? just curious
can we compare same with 3.9 vs 3.11 i think there should be huge difference
you don't ran the node script there was a error
Why did you code the c code so complicated? Line 1 and 2 are not needed.
¿Por qué mejor no lo pruebas con un algoritmo y de ordenamiento o búsqueda?
Excellent! ❤
You should've built the go binary first... surprised you're not aware of this... "go run" first has to build, then run - so it'll be slower.
dose vim works in pycharm???
9:46 💀bro really did node.main.js LOL
I understand your points. However, this is Python's fault.
My opinion is Python should give us to choose of assigning static variables and compile the code.
The default settings may be dynamic data types and interpreter, I have no problem with that, but that is the exact reason of why Python is slow.
As a user I would like to have an option to write code like C but in Python syntax (if I need speed), If I do not, then I could write code as the default Python settings. But that should be my choice.
for example, age is an integer value, the interpreter should not "have to" check in every single time. (By the way it is has to be a positive integer value between (0, 127), if I write that in C, I defined it as char age; So, more optimizations can be made)
I have no idea about why they do not let us define any static value, static data type and compile my code (Interpreter great while developing but after final product developed, I prefer a compiled program.
Like.
const PI = 3.14
int age = 20
Cython does precisely this without having to learn a huge stack of C syntax.
The first task wasn't run for javascript, it failed and you only assessed the time it took to fail. Also, java should be compiled first for a real measurement
I want python to one day be faster than C#
So, python is fast, as long as the code actually runs o C++.
I love py & js
You should also add Rust and yea python is fast but not by default
One sample tells us less than nothing
wow, really amazing
Python 3.11 very fast
Full of loopholes
In java it takes just one line:
IntStream.range(0, 1000000000).sum()
hey neural, theres an issue with your machine learning bot, we think the library is broken but not sure, please can you take a look
Is this guy an amateur pretending to be a professional? Either that or he's trying really hard to "sell" python. I see no other justification for such a terrible video.
First and foremost, he doesnt write any "warmup" code that would allow some languages to have lower times on the benchmarks. He could then compare that to the version without said "warmup" code and see how large the difference is or isnt.
Secondly, he does one run and thats it. No averages whatsoever. And to make matters worst, he's measuring compile times, for example, for java. Ridiculous honestly. He's also not using any optimizations for C which is just as ridiculous.
Finally, I like how he tries to "sell" python at the end by comparing a version using a library to versions of Java and C without library. Yeah, python development speed is faster, but if you use Java and C libraries you can make those languages almost as fast development wise.
Like c'mon man, at least put some effort into it.
Edit: he also complete ignores different implementations of interpreters and compilers for each language which can produce very different results. What a joke of a video
R. no se escucha mucho como lenguaje de programación de alto nivel, pero me gusta su sintaxis.
Only mean to criticise constructively dude, your methodology is severely flawed. You are measuring the compile times along with the execution times. You should be compiling binaries and measuring execution speed of those.
Never noticed his mistakes in previous videos?
First of all, end-to-end measurement you are doing is completely incorrect. You should've done it inside of your scripts.
Second, with python it is REALY hard to work on complex projects, since there is no type system (the one python has is a joke), hence the development speed would slow down dramatically as the project grows.
Not hating on python, I think it is a great language for small projects and scripting.
UA-cam was/is written in Python.
You can create a virtual type system using MyPy. Google and Facebook even developed their own versions of it. It's not going to make execution any faster but it helps a lot in terms of development and working on complex projects.
He’s definitely a Croat that’s living in Germany, looks like Mirko cro cop too
n 1