Node -does- compile under the scenes, so once everything's optimized as part of that compilation, I'm not shocked that the results are similar. It's just a sign that the optimization is well done, at least for simple math like this. The big advantage you'll get with native C++ is doing things Node doesn't support - things that specifically target the operating system, things that access memory directly, or things that are optimized for the specific hardware you're running on. I do wonder if there's any overhead to loading the C++ module, and when that occurs. Is it loaded dynamically or is it part of the compilation? I've got a ton to learn about this...thanks for the starting point!
i did this experiment with java years ago and got the same confusing results. Then I switched from just numbers to something that allocated a million integers and added them up, and STILL got the same answer you are seeing, but then I forced java to garbage collect the memory of the array and the run time was dramatically larger for java than for c++. The thing is, in real world applications, sometimes the interpreter is plenty fast enough -- especially if you exit before garbage collecting. You will see c++ winning when you are creating huge amounts of memory in small fragments that must be garbage collected in the interpretive application. So long as there is no garbage collection, you may ever see c++ clearly win. Choose the right language for the problem and be aware that testing is complex. Also be aware that figuring out how to fix a garbage collection problem is not easy... though modern tools may help a lot.
Node is kinda the type of variable in javascript(on v8/ c++ level), unless you change the type of variable oi runtime it will be really fast with numbers. Good work buddy
please reply, does this actually run the c++ code(at c++ speeds)? or does it just convert the c++ code to javascript and then run that javascript in node? because if its the latter that would explain why they're running at equal speeds, I started using this in my project because i thought it would give me the performance boost from using c++ that I needed. have I understood this whole thing wrong?
Whenever I try to include the node.h, it gives me error saying it's not included in path. I already have all packages installed where I was working with napi.h before but encountered some problems and decided to follow your tutorial so any suggestions how to fix it?
Maybe a bit late. However, I guess that it is the IDE/tool telling you that it's not included in the path. Node-gyp has its own header files, ignore what your IDE/tool says and configure then build. Worked for me, thanks!
Hi, Firstly thanks for your video! Could you explain how make the same thing but using another C++ libraries as well ? No native libaries, another ones like Armadillo or Eigen.
i wish you had actually showed "the install process" and not just said "i already have it installed" because i am running into problems installing the dependencies!
Thanks for tutorial. Btw did anyone get why C++ and js taking same time for this functionality? I am also getting same results on my mac. Is it because of window/mac or anyone tried it on ubuntu?
In my main file (addon.cpp) I have included a header file (prova.h), located in an src folder that I created. The function that it declares is implemented in the prova.cpp file (located in the same directory). This is the content of the addon.cpp file: #include #include "src/prova.h"//
Node -does- compile under the scenes, so once everything's optimized as part of that compilation, I'm not shocked that the results are similar. It's just a sign that the optimization is well done, at least for simple math like this.
The big advantage you'll get with native C++ is doing things Node doesn't support - things that specifically target the operating system, things that access memory directly, or things that are optimized for the specific hardware you're running on.
I do wonder if there's any overhead to loading the C++ module, and when that occurs. Is it loaded dynamically or is it part of the compilation?
I've got a ton to learn about this...thanks for the starting point!
This tutorial is a hidden jewel. Thank you sir!
Thank you for leaving your value typo in there. It was fun to try to spot the error before you, and that got me engaged and invested in your video.
Thanks glad you like it :)
i did this experiment with java years ago and got the same confusing results. Then I switched from just numbers to something that allocated a million integers and added them up, and STILL got the same answer you are seeing, but then I forced java to garbage collect the memory of the array and the run time was dramatically larger for java than for c++. The thing is, in real world applications, sometimes the interpreter is plenty fast enough -- especially if you exit before garbage collecting. You will see c++ winning when you are creating huge amounts of memory in small fragments that must be garbage collected in the interpretive application. So long as there is no garbage collection, you may ever see c++ clearly win. Choose the right language for the problem and be aware that testing is complex. Also be aware that figuring out how to fix a garbage collection problem is not easy... though modern tools may help a lot.
Node is kinda the type of variable in javascript(on v8/ c++ level), unless you change the type of variable oi runtime it will be really fast with numbers. Good work buddy
Man you saved my life, thank you!, it worked perfectly.
You are welcome
This is nice!!! Advanced stuff, good job!
Thanks!
If anybody is using a Mac, you will need to install the necessary tools. So, you can run this command: xcode-select --install.
Thank you for your great tutorial! You really helped me!
You are welcome bozz!
WOW! Thank you so much!
You are welcome!
Can you make a c++ function that accepts js values and returns values that will later be used in node.js?
Shouldn't c++ be faster in the runtime than js?
please reply, does this actually run the c++ code(at c++ speeds)? or does it just convert the c++ code to javascript and then run that javascript in node? because if its the latter that would explain why they're running at equal speeds, I started using this in my project because i thought it would give me the performance boost from using c++ that I needed. have I understood this whole thing wrong?
Thank bro, you really helped me out !
You are welcome!
Whenever I try to include the node.h, it gives me error saying it's not included in path. I already have all packages installed where I was working with napi.h before but encountered some problems and decided to follow your tutorial so any suggestions how to fix it?
Maybe a bit late. However, I guess that it is the IDE/tool telling you that it's not included in the path. Node-gyp has its own header files, ignore what your IDE/tool says and configure then build. Worked for me, thanks!
@@johansaltin8187 I was going crazy over this issue, thank you!
doubles are pretty performance consuming. Try to convert it to long, and you will see the huge difference.
Hi, Firstly thanks for your video!
Could you explain how make the same thing but using another C++ libraries as well ?
No native libaries, another ones like Armadillo or Eigen.
i wish you had actually showed "the install process" and not just said "i already have it installed" because i am running into problems installing the dependencies!
Thanks for tutorial. Btw did anyone get why C++ and js taking same time for this functionality? I am also getting same results on my mac. Is it because of window/mac or anyone tried it on ubuntu?
i am also confused both are taking almost same time in ubuntu
Hey, man, how you doing?
I have a question, is there a way to return the value of the function to a variable?
i did the exact same thing , c++ was at least 12 time faster
is this possible to do with mac?
In my main file (addon.cpp) I have included a header file (prova.h), located in an src folder that I created. The function that it declares is implemented in the prova.cpp file (located in the same directory). This is the content of the addon.cpp file:
#include
#include "src/prova.h"//
I just solved my problem by deleting the build folder and rebuilding.
nice tutorial but you should type in title with "Hello World" that is better for noob.
Here you got it: nodejs.org/api/addons.html#addons_hello_world
OMG what a nice voice?
Thanks
your video is soo good and simple ... could you please tell me which node-gyp version you used?
Thank you! node-gyp v ^6.0.0
I think if you run c++ clean, the results will change
Could you explain how to run c++ clean with c++ code in this video, please?
OOMMGG
change double to long
Wouldn’t that produce an incorrect result of the c++ algorithm compared to the result of the js algoritm? I mean due to precision differences
@@FullstackDevelopment i do not know,but of changing to long ,it becomes faster