Solved

Node.js Vs C or Node.js Vs C++

Posted on 2013-11-05
13
3,594 Views
Last Modified: 2013-11-11
Dear Experts,

I have done my created huge math function such as order 20 of polynomial/regression function with 10,000 data input in PHP program.
After math calculation is done , I will echo out the output
to the client browser. Since the function is huge almost
costing it  15 seconds to finish, I want to replace the math
function by other languages.

Recently, I heard javascript on server-side, Node.js,  so  
I know javascript is much easy to use as PHP coding , and I check
its speed is much faster than PHP as C

So now I try to make desicion on switch programming Lanauge on Javascript
or C or C++

But C or C++ is really time consuming to get to know everything such as
its complicated pointer structure or its sytnax

How do you think about using Javascript to do huge math function instead of
using C or C++ ?

And what is major different between C and C++ in doing huge math function ?

Or other lanaguage could handle huge math function code with good code and speed, please point it out ?

Please advise

Duncan
0
Comment
Question by:duncanb7
13 Comments
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
Comment Utility
You're talking about two different programming paradigms. Javascript is a scripting language that is intended to be run by a host; C and C++ are compiled languages which can be built into standalone executables. By default, C and C++ will run faster than Javascript since they are compiled directly into machine code (i.e. code that runs on the processor). For complicated match functions, I would expect that C and C++ will offer better performance, unless of course you can find a Javascript compiler. (Perhaps one exists, but I haven't heard of it. Perhaps someone else can speak to its existence.)
0
 
LVL 13

Author Comment

by:duncanb7
Comment Utility
Yes, I check the speed in Node.js and C that is similar doing
1e10  times of addition/subtraction  math,

And yes javascript is interpreted language not complied language
but Node.js is running much faster than PHP that is also interpreted language.

Also  it can be running as background process with http request which is
the task will fire on request once it is running on system set up in advance

And Node.js emphasis on concurrent process that  is much faster  than
other language.


Anyway, I prefer to take back C or C++ because I don't want to take a risk
to try new

Shoud I use C or C++ ? which is better just for huge  math function ?

executed or Complied code should run faster than interpreted code
0
 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 100 total points
Comment Utility
C and C++ are essentially identical when it comes to mathematical processing - C++ is an extension to the C language to provide object orientation and other extensions.

It will be faster but if you are interacting with a browser you are going to have to write it so that it can interact with the web server (using CGI or as an extension).

As far as I know node.js is a framework for writing server side code - it may be useful for your purposes but javascript is the language there - node.js is just the framework.

One option is to write the heavy stuff in C - have the script kick that off - which writes to a file. When complete the script reads the file and returns the results to the browser.
0
 
LVL 13

Author Comment

by:duncanb7
Comment Utility
I am planning write a C running in PHP with exec() command

for example,

<?php

php code
....
....
test=exec("../../C/mymath order data test.csv");
file_get_content("test.csv")   //which is done by C language and save the result into a file


php code for web handling


?>
0
 
LVL 13

Author Comment

by:duncanb7
Comment Utility
It will be faster but if you are interacting with a browser you are going to have to write it so that it can interact with the web server (using CGI or as an extension).

What you mean CGI ? php is CGI script  langauge already , right ?
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
I meant if you wanted to interact directly with the C program.

Given you are going to be exec'ing the prog that does the intensive math calcs - the host environment (PHP / Java) is irrelevant and should give you no performance benefit either way.

If you are going to use PHP you should have a look at the set_timelimit function (http://php.net/manual/en/function.set-time-limit.php) to ensure your script does not timeout before the math app completes.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 13

Author Comment

by:duncanb7
Comment Utility
So what you mean, please advise


Given you are going to be exec'ing the prog that does the intensive math calcs - the host environment (PHP / Java) is irrelevant and should give you no performance benefit either way.


Even max_execution_time or set_timeout is no issue at al,
you mean I don't have any benefit to run C using exec() in php, RIght ? WHy ?

Or

I need to rewrite all PHP code into C instead rather than just some math cals code
that might speed it up  by not using PHP environment or PHP slow engine, RIght ?


Please advise it in detail

DUncan
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
you mean I don't have any benefit to run C using exec() in php, RIght
No - definitely not. If you can write the app in C then it is the best solution for performance.

What I meant was  - if you are going to write your math intensive code in C and then launch that from a server side scripting environment - then the scripting language you use is irrelevant because it is not really doing anything. The performance is going to be dictacted by the speed of the C app.

In other words PHP launches C app vs Java launches C app vs .Net launches C App is much of a muchness.
0
 
LVL 22

Accepted Solution

by:
ambience earned 300 total points
Comment Utility
Perhaps you should also consider a PHP cross compiler like HipHop (http://en.wikipedia.org/wiki/HipHop_for_PHP) that converts PHP code into C/C++. Facebook created that to solve their performance issues. It may not be as efficient as hand-coded C/C++ stuff but still worth looking.

There are several cross-compilers actually.
0
 
LVL 13

Author Comment

by:duncanb7
Comment Utility
Is HipHOP similar to Zend framework or Zend php or Zend server

http://en.wikipedia.org/wiki/Zend_Framework

that also is process to get better php code optimization  from converting some part php
code in php file into C/C+= coding ?




I run command "zf  show version " that is checking version of zend framework and it showed
zend is not installed.

How I can know whether my server is already installed HIPHOP or not ?

Please advise

Duncan
0
 
LVL 13

Author Comment

by:duncanb7
Comment Utility
Dear Ambience and JulianH


Could you reply my last post and read this new thread

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28287892.html

Please advise

Duncan
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
I have no personal experience with HipHop.
0
 
LVL 13

Author Closing Comment

by:duncanb7
Comment Utility
Thanks for all of reply , your attached link is helpful a lot to the issue.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now