Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-11-05
13
Medium Priority
?
4,431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 300 total points
ID: 39625214
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
ID: 39625260
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 59

Assisted Solution

by:Julian Hansen
Julian Hansen earned 300 total points
ID: 39625274
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

by:duncanb7
ID: 39625290
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
ID: 39625294
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 59

Expert Comment

by:Julian Hansen
ID: 39625578
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
 
LVL 13

Author Comment

by:duncanb7
ID: 39626357
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 59

Expert Comment

by:Julian Hansen
ID: 39626453
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 900 total points
ID: 39627075
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
ID: 39628070
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
ID: 39630103
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 59

Expert Comment

by:Julian Hansen
ID: 39630346
I have no personal experience with HipHop.
0
 
LVL 13

Author Closing Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

670 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