Skip to content
Sign upLog in
← Back to Community

C++ and Node.js

Profile icon
Highwayman

Ok, so to start this off we just have to reestablish the fact that I am weird, and absolutely insane.

Ok. Here goes...

I recently discovered that C++ can be bound in node.js as a module type thing and node and C++ are basically the only two languages that I know well. Now this being said, I am thinking I’ll do a completely C++ run massively multiplayer game, but with node.js handling the networking and the database operations. Now that being said, this could all be done in straight up c++ if I wanted to learn, but I don’t know if that’ll even really have any performance benefits. I know it won’t have development benefits lol I don’t feel like learning more low level stuff at the moment.

So what I’m asking is what do you guys think in terms of common sense and do any if you guys happen to know whether the performance advantages of switching to C++ are negligible or not.

Thanks!

Answered by eco27 [earned 5 cycles]
View Answer
Voters
Profile icon
AkramBouattou
Profile icon
eco27
Profile icon
Highwayman
Comments
hotnewtop
Profile icon
eco27

c++ and any compiled languages in general are much faster than node. so to answer your question, yes, c++ would offer a giant performance advantage. example benchmark site:

image


however, I don't think you need to worry about performance. think of it like this: you are choosing between a racecar and a rocket for the task of going 10 miles on a flat road. both will do it really fast, even if the rocket is a little faster. I would actually recommend you use node.js for its advantages of better readability, better networking as you mentioned, and also lots of packages with npm easily installed.

tl;dr
c++ is faster than node
however, in your case the performance difference wont matter as both languages are pretty fast. I recommend node for its advantages.

Profile icon
Highwayman

@MrEconomical
thanks! That’s exactly what I was looking for, though I must say I’m a little confused on your example; wouldn’t making a game be an intensive program, making that performance boost worth it?

Profile icon
eco27

@Highwayman
consider this: node.js can do ~2 billion operations per second. let's say you have 1000 players. each player requires 100 operations every tick. that's 100,000 operations in total per tick. at this rate, you can still run your game at 20k ticks per second.

Profile icon
Highwayman

@MrEconomical
:/ Ok. My brain both won’t accept that fact and will accept at the same time. XD thank you :)

Profile icon
mwilki7

Depends on how computationally intensive the game is.
For massively multiplayer, it seems the networking would be the bottleneck in performance. That seems more like a networking problem than a language problem.

Though, mixing C++ and Node sounds like an interesting project.
I disagree that C++ is less readable. Anything can be hard to read with bad programming practice, although it IS a heck of a pain to do socket programming (C++ 50 lines vs Node 3 lines (or less?)).

I would say go for it.

Profile icon
Highwayman

@mwilki7

yeah, that’s what I was thinking, but yeah Idk s**** lol.
It definitely is gonna be, I’m still trying to pieces together at all rn.
I’m not saying that it is less readable, I am saying that it would be harder to learn those 50 C++ lines than just learning the 3 node lines. :P

Profile icon
Highwayman

Update2:
Found the header. It’s in usr/include/node (I’m so dumb lol)

Profile icon
Highwayman

Update: it repl.it doesn’t have the c++ header I need to do this :’(
Maybe I haven’t tried hard enough when looking, but I’m pretty sure it just doesn’t exist on repl.it.