Python vs JS vs PHP for embedded systems

I've got a question about which programming language is preferable for developing websites in the embedded system (hence with some limited resources). Here is my small investigation in a table form.

 PythonJS (node.js)PHP
Runtime Size (Gentoo Linux x86)~1.4Mb (/usr/lib/libpython3.1.so)~3.2Mb (/usr/lib/libv8.so)~7Mb (/usr/bin/php)
Type SystemStrong TypingWeak TypingWeak Typing
Vulnerabilities867324501
Performance35.425.3562.45
OptimizationPsyco (up to 100x)V8 JavaScript engine is already optimizedPHP Accelerators
DocumentationExcellentAveragePoor
C BindingsExcellentAveragePoor
Code ReadabilityWith PEP8 it can be perfectEven with Google JavaScript Style Guide it can be a messPEAR Coding Standards can't help it
DebuggingExcellentAveragePoor

My totals: Python - FTW, JS - AVG, PHP - KMN :-)

Additional notes (I didn't include them in the table due to its irrelevance in some cases):

  • Python is supported on enormous amount of platform, PHP - on slightly less, V8 - only on Linux/Windows/MacOSX.
  • Sometimes compiling V8 can be tricky depending on target platform.
  • PHP is highly redundant and don't have thorough naming conventions for its functions (just take a look to its string functions).
  • People matter - for example, if you don't have PHP experts in your team, it can be risky to use it for development due to its pitfalls.

I someone want to share ideas and other criteria you're welcome!

Comments

  1. And can use Python on Windows CE6/7 (embedded systems) too.

    ReplyDelete
  2. Your comparison seems a little bit biased toward Python. Node.js is a really new project compared to Python and PHP.

    A fair comparison would be cross-compiling the three softwares and creating the same sample application for each one. Then you could measure development time and performance running on an embedded board.

    ReplyDelete
  3. I agree, but frankly I'm really not so sure about running Google V8 on an embedded platform at all. I had some problems with its compilation even on standard PC, and I assume that it can be a nightmare to make it work on some limited platform.
    Anyway it can take a lot of time, and I can't do fair comparison now. For example, the embedded platform which available for me and can be used for that task is a certain kind of Linux and have only GCC compiler on it. To compile V8 I have to setup C++ toolchain, and even this task is pretty challenging.

    ReplyDelete
  4. Don't underestimate that last option. Having people with experience in your chosen language is probably the most important factor.
    Surely Java, C and even Perl would also be options

    ReplyDelete
  5. In the most cases I would agree with you, but embedded systems have its own peculiarities, which change the importance of the "experience" factor. In some cases it would be more profitable and efficient to train personnel to master in some other programming language.

    Let me provide the example. I'm developing for embedded systems in C now, and one of these have firmware size limitation. So we have to use stripped libraries because symbols take more than 10 Mb. Recently we've got a segfault, and it took several hours to find the reason (because core dump didn't contain even module name). I bet it could take just few minutes if website were developed using a high level programming language.

    Regarding "Java, C and even Perl" - yes, it would also be options, but my initial question was only about Python, PHP and JS. Of course, there are other good options including Lua, Erlang, Ruby etc, but it's a theme for another research.

    ReplyDelete
  6. The target application, as much as the target platform need to drive these decisions.

    Before I get into it though, I wanted to point out that the vulnerability count you are using for nodeJS is based on all javascript engines, that the actual count for Chrome V8 and nodejs is in the twenties. Also, if you compare the performance of Chrome V8 with the other languages in your article, instead of Java which is the default on that page, that except for operations which require fast floating point operations, Chrome V8 (the engine in NodeJS) out-performs both Python and PHP in speed and memory utilization (which is very important in an embedded system).

    PHP is very mature, so has had a chance to be optimized to death. (I will keep my opinions about how that death has crept into other aspects of PHP to myself, or would if I could help it.) As a result of having been optimized heavily for speed over the years, it is VERY fast but also VERY large, an obvious handicap for embedded work. Otherwise a great tool for its original intended purpose. Dynamic generation of web pages on a full fledged server or cluster.

    I do not have a lot of experience with Python, so cannot comment fairly on it's merit relative to PHP or NodeJS, however I have some thoughts that are not TOO evangelical.

    While modules exist for python to enable its use as a webserver (tornado), they generally require getting additional software to compile on the embedded environment, further complicating the process. To Python's credit, its pretty fast and strong typing is valuable in many projects.

    My final thoughts (today). Both PHP and Python have their place, but what exactly are you trying to accomplish on that edge device? If you are building a computation engine in an embedded box, I have to ask WHY? If like most software on embedded systems your goal is to create a network service, you need to re-evaluate nodeJS. It has several HUGE advantages.

    NodeJS has simple to use libraries for acting as a web or socket server directly. Compared to tools like PHP and perhaps Python that would require a separate process for handling web/network requests, this is a huge advantage as it reduces kernel calls and complexity by at least one IPC (inter-process communication) channel.

    As with any project, choosing a tool must involve a realistic understanding of how it is to be used. Since my case is a network service, I have to go with the tool that makes best use of the VERY limited resources available in an embedded environment that also fits the type of application I am building, in this case NodeJS.

    Lastly, I have built NodeJS for an arm embedded using ELDK. There were several hurdles but nothing insurmountable.

    ReplyDelete
  7. Chrome V8 is way much more advanced than Python and PHP. It is built on the concept of Asynchronous I/O. Moreover Google has already released a version of V8 that can be compiled on a bare metal platform (without OS) with only C++ libraries. Socket.IO using V8 and nodejs can be used develop real time web apps with always open socket connection between http client and server same as HTML5 websockets with advantage of older browser support. HTML5 websockets are supported by only some of latest browsers.

    ReplyDelete
  8. Now,there is the PH7 engine project which is an embedded PHP engine that allow C/C++ applications to compile and execute PHP programs in-process (very useful to build web administration interface for application).
    Here is the link: http://ph7.symisc.net/

    ReplyDelete
  9. Late to the game here, but key point missed. Both PHP and Python are intended for server side web processing while JS runs on the client. Big difference. Also, since JS.node is written in C++, it's probably a good bit slower (C++ uses vtables and, depending on coding style, can grow the app large and slow, e.g., with several levels of inheritance.) I've been doing this a looooong time (40 yrs - yes four-zero) and web stuff does more, consumes much more memory, and is slower despite new tech and faster processors.

    ReplyDelete
    Replies
    1. Frankly, we had to fallback to C extensions for the most CPU-consuming tasks, neither of the server-side classic platforms are good fit for complicated embedded systems (however, I didn't test recent versions of Go and Rust).

      Delete

Post a Comment

Popular posts from this blog

DIY: Business cards in LaTeX

Shellcode detection using libemu