Benchmarks: Node.js vs Go vs PHP

With talk lately about Go, the Google sponsored programming language), and what performance benefits it holds, I thought I’d go and do a quick benchmark of Go, Node.js, and PHP.

Update: Node.js vs. Go 1.1

Disclaimer: Make the smartest decision possible when choosing a language. Benchmarks give you a rough idea of language speed, but do not provide insights into real world usability, productivity, or what is best for you or your company. In short, take these numbers wisely.

The test

Here’s the first test. A rusty old Bubble sort. I use this because it gives a good idea of how long computations and comparison operations take for the specific language to perform. Here’s the code I used:

PHP

<?php
$starttime = microtime(true);

$array = array(3,4,1,3,5,1,92,2,4124,424,52,12);

for ($c=0;$c<100000;$c++) {

for ($i=0;$i<count($array);$i++) {
    for ($y=0;$y<count($array)-1;$y++) {
        if ($array[$y+1] < $array[$y]) {
            $t = $array[$y];
            $array[$y] = $array[$y+1];
            $array[$y+1] = $t;
        }
    }
}

}
print_r($array);
echo microtime(true) - $starttime;

Node.js

var starttime = new Date().getTime();

var array = [3,4,1,3,5,1,92,2,4124,424,52,12];

for (var c = 0; c < 100000; c++) {
    for (var i = 0; i < array.length; i++) {
        for (var y = 0; y < array.length - 1; y++) {
            if (array[y+1] < array[y]) {
                var t = array[y];
                array[y] = array[y + 1];
                array[y + 1] = t;
            }
        }
    }
}
console.log(array);
console.log(new Date().getTime() - starttime);

Go

package main

import "fmt"
import "time"

func main() {

timestart := time.Now();

array := [...]int16{3,4,1,3,5,1,92,2,4124,424,52,12}

for c := 0; c < 100000; c++ {

for i := 0; i < len(array); i++ {
    for y := 0; y < len(array) - 1; y++ {
        if array[y+1] < array[y] {
            t := array[y]
            array[y] = array[y+1]
            array[y+1] = t
        }
    }
}

}

fmt.Print(array);
fmt.Print("\n");

timeend := time.Now();

fmt.Print(timeend.Sub(timestart));

}

Without further ado, here are the results:

Holy slow is slow, PHP. That’s a full three seconds, verses the less than 100ms boasted by Node.js and Go. Let’s remove the outlier:

PHP completed the operations in 3.835 seconds. Node.js completed them in 71 milliseconds, whereas Go completed them in 38ms. Not bad, those latter two.

Conclusion

As a language, Go does seem faster than Node.js by a significant margin. This being said, the two are both eons ahead of PHP in speed, which we all already knew. The performance gains from both of them, compared to PHP, shows they are both relatively fast when compared to a very popular language for web development.

Test 2: HTTP

Now, since we’re talking in the context of the web, I thought I’d compare Node.js and Go’s HTTP capabilities.

Go

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "You requested %s", r.URL.Path)
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Node.js

var http = require("http");

http.createServer(function(request,response) {
    response.writeHeader(200);

    response.write("You requested " + request.url);

    response.end();
}).listen(8080);

Without further ado, the ApacheBench results:

Again, lower is better. In this case, Node barely outperformed Go in handling static HTTP requests, but not by much of a margin (~1ms).

Now, if we throw the bubble sort code into the request handler function, we get obviously this:

Here, the computation efficiency of Go wins over Node.js. But computing 100,000 bubble sort operations is probably not on the scale of data processing is required per request to your users, so we’ll drop the loop and do one bubble sort per request:

Now that’s interesting. Here, it appears that the HTTP transport of Node.js is more efficient than Go’s, despite the lower computation speed. If we increase the concurrency, the gap between the two grows:

Conclusion

My only strong conclusion from this is, if your goal is to optimize past the speeds of PHP or other similar languages, Go and Node.js are good alternatives. Which should you use? This information can’t tell you that. It would appear, and make sense, that Go handles data processing more efficiently than Node. But at the same time, it does appear that Node may scale more efficiently, at least in the almost pure HTTP side of things. In a real world scenario, the type of operations your application does will be critical in determining this. One thing I didn’t benchmark, and I wish I had time to, is database driver speeds, but that’s another topic for another time. In the end, though, I’d say language choice is truly up to preference and suitability for your project. Go may be somewhat faster in a few cases, and Node in others, but both Node.js and Go are eons faster than PHP. It truly depends on your team’s experience and what type of operations are at hand.

Any questions, suggestions, or better points are welcomed (and encouraged)

Update: Node.js vs. Go 1.1

Source

من يدير جوجل؟

من يدير جوجل؟

مقال رائع جدا للاخ محمد حجاج

Genetics, Nanotechnology and Robotics

http://www.ibda3world.com/who-manages-google/

روشتة لنمط حياة صحي لكبار السن في مصر لتجنب العديد من الأمراض

قدم الدكتور سامح علي ، رئيس مركز دراسات أمراض الشيخوخة بمعهد حلمي للدراسات الطبية ب #مدينة_زويل لموقع “ #الوطن #علوم و #صحة ” روشتة لنمط حياة صحي لكبار السن في مصر لتجنب العديد من الأمراض.

قال الدكتور سامح أن أمراض الشيخوخة تكبد دول العالم الكثير من الأموال لرعاية الأفراد صحياً في حال إصابتهم بالأمراض بخاصة بعد التقاعد يقدر في معظمها بمليارات الجنيهات. في ظل إرتفاع معدل عمر المصريين منذ الأربعينات من 50 إلي 70 عام.

“تأخر متوسط العمر الصحي لكبار السن في مصر بعشرة سنوات مقارنة بباقي دول العالم” ، أضاف سامح في إشارة لمعاناة المسنين في مصر من تدهور الحالة الصحية والإصابة بأمراض متوطنة مثل السكر و القلب ؛ ما يزيد من معاناة موازنة الدولة في تقديم الرعاية الصحية.

يرتبط التدهور الصحي لكبار السن ،كما أضاف سامح بوجود أخطاء في نمط الحياه و الإبتعاد عن النمط الصحي في الغذاء أو حركة الجسم أو الحالة النفسية ؛ مايجعلنا نقدم روشتة نحو شيخوخة أكثر صحية.

نوعية الغذاء الصحي لكبار السن

علي مستوي التغذية ، يفند مدير مركز أمراض الشيخوخة ما أسماه بأسطورة “أن الغذاء الصحي مكلف” ،موضحاً بأن الوجبة الغذائية الصحية يمكن أن تكون أقل تكلفة .و يعتمد البرنامج الغذائي الصحي علي تناول الخضروات و الفاكهة و التقليل من النشويات و التركيز علي اللحوم البيضاء علي حساب اللحوم الحمراء لزيادة المواد الدهنية في الأخيرة التي تضر بالقلب بجانب التركيز علي زيت الزيتون في طهي الأطعمة.

أشار سامح لضرورة تناول المكسرات ، التي تعد مصدراً للدهون غير المشبعة التي تحتاجها خلايا جسم الإنسان للقيام بوظائفها ؛ بخاصة الفول السوداني و عين الجمل . و الإبتعاد عن المشروبات الغازية التي تعجل بالإصابة بأمراض البدانة في حال الإفراط في تناولها ،و تجنب العصائر المحفوظة و إستبدالها بالطازجة.

شددت روشتة رئيس مركز أمراض الشيخوخة علي تناول المياه بما لا يقل عن 2 لتر يومياً ،وهي الكمية التي يحتاجها جسم الإنسان بخاصة كبار السن.

ممارسة الرياضة و التنشيط الذهني

نبه الدكتور سامح لضرورة ممارسة الرياضة سواء في الصالات الرياضية أو بممارسة رياضة المشي لمدة ساعة يومياً أو رفع بعض المواد الثقيلة التي تساعد علي تنشيط معدل التمثيل الغذائي لفترات طويلة ،بجانب التنزه بالأماكن المفتوحة و إستنشاق الهواء النقي.

فيما يتعلق بالنشاط الذهني اثبتت الدراسات ، كما ذكر الدكتور سامح أن تنشيط الذهن بحل الألغاز أو القراءة يساعد في إطالة العمر ،و الإبتعاد عن مصادر التوتر منها متابعة الأخبار السيئة للحفاظ علي الثبات النفسي لكبار السن.

إضطراب النوم والأمراض النفسية

نعت رئيس مركز أمراض الشيخوخة إضطراب النوم “بالأهم” للحفاظ علي التوازن الهرموني داخل جسم الإنسان ،بعد تغيير نظام النوم الطبيعي بالإستيقاظ حتي وقت متأخر من ساعات الليل و الخلود للنوم خلال فترات النهار ؛ ما يخل بوظائف جسم الإنسان التي تعمل وفقاً لساعة بيولوجية تتأقلم مع الضوء في حال شروق أو غروب الشمس.

و يتسبب الخلل بالساعة البيولوجية ،كما أضاف سامح في فقدان التركيز و قدرات التعلم و الإصابة بعدد من الأمراض النفسية علي رأسها الإكتئاب والإصابة بأمراض البدانة لتأخر معدل تكسير الطعام خلال فترات الليل.” lموقع الوطن – مقال “رئيس مركز أمراض الشيخوخة يقدم روشتة لنمط حياة صحي لكبار السن

Embedded Systems Projects Ideas for Engineering Students

List of Embedded Systems Projects Ideas:

SNO
Project Title
1
Auto Power Supply Control from 4 Different Sources: Solar, Mains, Generator & Inverter to Ensure No Break Power
2
Automated Car Dash Board
3
Automated Town Water Management System Using PIC
4
Automatic Door Bell with Object Detection
5
Automatic bidirectional visitor counter using 8051 microcontroller (AT89C51)
6
Automatic plant Irrigation (AT89C2051)
7
Automatic College Bell (AT89S8252 & DS1307)
8
Automatic Dialing to Any Telephone Using I2C Protocol on Detecting Burglary
9
Automatic Door Opening System with Movement Sense
10
Automatic irrigation System on Sensing Soil Moisture Content
11
Automatic Room light Controller with Visitor Counter (AT89S52)
12
Automatic Surveillance Camera Panning System from PC
13
Cell Phone Based DTMF Controlled Garage Door Opening System
14
Cell Phone Controlled Robotic Vehicle
15
Celsius and Fahrenheit scale digital thermometer using 8051 microcontroller (AT89C51)
16
Celsius scale digital thermometer using 8051 microcontroller (AT89C51)
17
Clap counter using 8051 microcontroller (AT89C51)
18
Remote Jamming Device
19
3 LED Bike Light using PIC10F200
20
3-Switch Mini IR Remote Control Continue Reading →
PHP Template Engine Comparison

Summary (assign)

Test tot. time tot. memory package size
php 5.4.4-14+deb7u5 2001 μs 12.16 KB 4 KB
raintpl 2.7.0 5113 μs 321.86 KB 37 KB
twig 1.5.1 17671 μs 844.86 KB 647 KB
smarty 3.1.11 20411 μs 1.52 MB 1100 KB

Source

Seven step process to increase knowledge

1) Learn to be more observant
2) Learn to find everything interesting
3) Learn to question everything 

And then

4) Travel
5) Talk to people
6) Read
7) Create projects

5 features to know about Composer PHP

1. Update only one vendor

You want to update only one specific library, without updating all your dependencies? That’s easy, just add the vendor name as argument to the update command:

$ composer update foo/bar

This will only install or update the library (plus its dependencies) and overwrite thecomposer.lock.

Nevertheless, this is also very usefull to fix a warning message I’m sure you know very well:

Warning: The lock file is not up to date with the latest changes in composer.json, you may be getting outdated dependencies, run update to update them.

« Damn it composer, what’s wrong with my vendors? ». Don’t panic! This is what you should expect if you just have edited the composer.json file. For instance, if you add or update a detail like the library description, authors, extra parameters, or even put a trailing whitespace, this will change the md5sum of the file. Then Composer will warn you if this hash differs from the one stored in the composer.lock.

Ok, so how to proceed? The update command is the one which update the lock file. But if I just add a description, I may not want to update any library. In that case, just update nothing:

$ composer update nothing
Loading composer repositories with package information
Updating dependencies
Nothing to install or update
Writing lock file
Generating autoload files

Thus, Composer won’t update your vendors, but it will bring your composer.lock file up to date. nothing in not a key word in the update command. Since it has no correspondence, it’s like you typed foobar. Note that since recently, there is a new warning message that tells you nothing is not a valid package, but that doesn’t matter.

Continue Reading →

Installing PHP 5.4 on Windows 7 for Developing With Symfony2

Overview

In this guide I hope to cover what you need to install to get your Windows 7 workstation configured with everything you need to develop with Symfony.

  1. Install PHP 5.4
  2. Install Xdebug
  3. Install APC opcode cache
  4. Install PEAR
  5. Install PHPUnit
  6. Install Recommended Extensions
  7. Symfony Config Check
  8. Install Git for Windows
  9. Install Composer
  10. Install PHP CodeSniffer and PHP CS Fixer
  11. Install ANSICON
  12. Conclusion

Continue Reading →

Why We Prefer Symfony 2 Over Yii Framework

Why We Prefer Symfony 2 Over Yii Framework

image

In this blog post I’m going to tell you a story that explain why our team preferred Symfony 2 over Yii which we used for a long time and doing our best to contributed something. How it happened and what caused us to make such a decision.

You might have thought that there was some big meeting where we decided that our next framework would be Symfony because blah blah blah. I’m afraid to disappoint you. The true story is more obvious and trivial.

Initially we were forced to use Symfony 2 as one of critical technical requirements in the project we were going to undertake. So we had a quick look at Symfony 2 documentation, cookbooks, new features etc. At that point in time everything looks very similar. Same MVC concept, just different template engine, ORM etc. Yes, Symfony 2 has dependency injection container but it doesn’t change things much. More over we have a few team members with awesome experience developing projects with Symfony v1.

We knew that migration would not be easy and that we will have to invest more personal time to maintain our normal development speed. We’ve just been open for new experience and another challenge.

 

This project has crazy deadlines. In addition, we’ve been using Symfony the same old way we used to do it in Yii. We tried to keep same principles, styles, approaches which we know works great for Yii. And that’s really was not a good idea. But it’s fine for the first time.

Next project was on Symfony too. There we tried to fix all misunderstandings and closely follow Symfony philosophy. Basically we have started doing things in Symfony-way and that fixed many architecture issues. Here we first time meet composer/packagist, PSR-2 and many other nice tools and helpers. Finally, we get closer to Symfony community.

I think only doing our 3d project we felt success and satisfaction from our new “venture”. Since that time we stopped considering Yii.

Now I will try to explain in more details why we decide to stay with Symfony. What we especially like. What are the most useful things.

Jumping ahead a bit I’d like to share results of our internal team voting. We’ve decided to ask all our team members in order to be sure that we are on the right way and if anyone wants to switch back to Yii. I was personally surprised that nobody voted for Yii. From the very begging some team members been skeptic, often criticize it saying that it is enterprise, Yii is simpler to develop and so on. But finally they let Symfony concept penetrate in their soul and now it is no way back :) They’ve made a few attempts in personal micro projects, but finally show the white flag.

So why we moved to Symfony 2?

Actually it’s all about code management and code maintenance. Perform code fast from the very beginning is really easy. We never had issues with this and I’m sure you too. Real issues shows up later, when project grows up and become long-term. Almost all our projects are long-term (from 2-3 months to a year or even more).

That’s why it is critical for us to use approaches and techniques to effectively manage our code in a long run. We had year-long projects in Yii. And it was hard to keep them nice after 3 month of development. We always have small issues, have to apply small workarounds, hooks and so on. Yeah, it works but no fun to support.

We want to keep our code base well-organized and follow some clear principles which will care about code and protect it from corruptions. That was our main concern. And no matter how long project is going. One month or one year. We want feel happy with our code anytime and keep interest in development. There shouldn’t be any hooks and workarounds. Honestly hooks are killing project team. Who like dirty laundry? It usually start like this: OK, today I will do this small workaround quickly and tomorrow I will find and replace it with better solution. Remember this point. It is a way into the abyss.

What code management issues we had in Yii?

TDD (test driven development)

First issue is code testing. Tests should be written easily. Nobody will follow TDD if one simple test requires mocking half of application services. It is a big overhead. And Yii wasn’t helpful enough.

Global service locator (Yii::app()) just killing attempts to write tests. You start with one test, then you understand that you need to mock this service and another one, and both of them depends on 3rd service… bah! Many services in Yii interact with each other. That sucks.

Then we have tight coupling. And it is tricky to perform application decoupling. Ideally we should not do this at all. It should be initially decoupled.

So it is really hard to follow TDD in Yii. Yes, they have CWebTestCase, fixtures, base integration with phpunit and so on. But that’s simple stuff. It is much more useful to test services/models without mocking other services, without mocking framework classes.

ORM/ActiveRecord

Having some ActiveRecords as framework core is fine. It’s really useful for beginner. But Yii active record is too simplified and again too tightly coupled. I know that when we talk about ActiveRecord we will most probably have tight coupling there because entity should get connection in order to save something without directly passing it. But that’s not the reason to extend this idea everywhere in the class.

More serious issue why Yii active record doesn’t fit our needs is because of missing separation between entity and entity manager (queries). In Yii we have to use static methods for querying models and non-static methods for model logic. In Yii ActiveRecord and ActiveFinder provided by a single instance. That’s not cool when queries mixed with entity getter/setter.

Another point regarding static methods for querying. Static methods can’t have state except for static one. And if you want to mix few conditions you have to merge criterias. With propel I do like this $query->filterByThis(1)->filterByThat(2)->find() and keep my filters/criterias separately. In Yii you will define them with arrays (you can’t create conditions dynamically) and then merge array or criterias. Quite boring job. Also I can’t have few query classes extended from base one, where I will separate filters/conditions based on domain business logic.

We need something more serious. In Symfony 2 we have Doctrine 2. Quite serious ORM with unit of work and other cool things. But it was too serious for us :) And finally we stick to Propel ORM.
I know it has some issues too and generated code far from best coding standards. But it works best for us and we get clear separation between entities and queries.
Main things we like about propel are: real getter/setter (we can have a look how they implemented and override them if needed), db schemas and migrations generation, behaviors that actually a generator addons, reach set of generator properties and integration in some Symfony components like forms and validator.

Code style

I know Yii team follows their own coding style and that’s fine. But internally we have different one and that was an issue.

Actually we did not have documented code guidelines before. We’ve made a few attempts to write them down but it was too boring writing about intentions, class names, brackets and so on. It require much time. We secretly had some common standards but it just wasn’t documented.

Problem is that our code guidelines were quite different for that Yii team use. We have contributed some extensions to Yii community and of course we wanted to keep our extensions similar to native Yii code. Finally we have to switch between different code guidelines all the time. For extensions we used Yii code guidelines, for real projects our own code style. Nothing cool.

We want to use something globally. In our code, in the components we use and in the frameworks itself.

Now we follow PSR-2. We were close to it and migration was super easy. Symfony2 follows PSR-2. Many components follows it too. It works for us and we really appreciate php-fig for their work. I know there are many polemics about PSR, but most of them about PSR-3. PSR-2 is good enough. At least for us.

One more things is namespaces. As you know Yii do not use namespaces. And it doesn’t help in building application. Namespaces helps to shortcut class names, helps with classes autoloading and so on. Overall we feel more comfortable with namespaces rather than without them.

Extensions

Let’s see how we used to get an extension in Yii. First we need to find it on Yii site, download, manually copy it to the project directory, attach it in config. Then we need to monitor Yii site for updates. It’s fine, but not in 2013.

Right now we uses composer. It’s really awesome when you can just define project dependency and run update. It will download extension/lib/component/bundle or whatever you want, setup autoloading and you can use it. Also composer will care about all component dependencies and download them. With one command you can update all components to most up-to-date version. You can specify which version to use. Maybe you want to download test and dev versions. That’s easy too.

There are some other things like contributing. It’s super easy to publish your package and make it globally available. It’s easier to define versions, easier to fork extensions, easier to send pull requests and so on.

Composer is extremely useful tool. That’s exactly what php community needs.

We use composer to manage our dependencies. We don’t keep external dependencies in our repos at all. What we need now is just keep composer.json in actual state.

Architecture

Let’s get back to code maintenance. Most often when people want to say that the code should be cleaner, they often say that they need the right architecture. What that means?

First of all that means that software should be based on some principles and follow good practices. So yeah, we want our software been principled. That’s why we try following SOLID and not follow STUPID. And Symfony helps us with this. Symfony 2 architecture relies on the same principles and that’s super awesome.

Final thoughts.

I want you to get me right. We still has warm feelings to Yii, keep saying best regards to Yii team, they did and doing great job. It’s awesome framework, and we spent several man-years writing code with this framework, contributed number of extensions and advised many beginners cross different forums. It just doesn’t fit our needs any more. We still follow updates regarding Yii2, and was waiting for Yii2 for so long… But we have to move. And the next point in our trip is Symfony 2.

source

10 أشيــاء يجـب أن تفعلهـــا قبــل أن تمـــوت !

الحيــاة – مهمـا طالت – قصيــرة جداً .. قصيــرة جداً لتقضي معظمهــا فى أمــور بائســة ، لا تفيــدك لا فى حيــاتك ولا بعــد ممــاتك ..

الكثيـــرون منكم يقضــون حياتهم فى جحيــم حقيقي منذ أن يستيقظ صبـاحاً إلى أن ينــام مســاءاً .. قلق ، اضطراب ، خوف من المستقبل ، خوف من الحاضر ، استحضــار لماضي كئيب ، تضييع الفرص ، الرعــب من المصائب المفاجئــة .. الخ ..

الحيــاة قصيرة جداً ياصديقي ، ومن الخســارة جداً ان تضيعهــا فى كل هـــذا الهُـــراء !

من فضــلك ، حاول ألا تمـــوت قبــل أن تقوم بهذه الأمـــور العشـــرة فى حيــاتك !

 ***************************

اقـــرأ .. واقــرأ .. ثم اقــرأ

1 القراءة 10 أشيــاء يجـب أن تفعلهـــا قبــل أن تمـــوت !

تذكــر دائمـاً ان الفرق الوحيــد بينك وبين الحيــوان – عفــواً – هو أنك تكتســب خبرات ، وتفكـــر .. واكتسـاب الخبرات والتفكيــر لا يتم إلا من خــلال المعطيــات ، التى غالبــاً تحصــل عليها من وراء القــراءة ..

عِش حياتك كلها قارئـاً .. حاول  ألا تدخــل قبــرك إلا وقد قرأت شيئــاً أو شيئيـن عن كل ما أثار اهتمــامك فى كل مراحلك العُمـــرية ؛ لأن القــراءة – ببساطة – هي الشيئ الوحيــد الذي يجعــلك تعيش حيــوات أخـــرى لم تعشها ، فى أزمنة لم تشهــدها ، وفى عقــول أشخاص لم ترهم ولم تمــر بظروفهم ..

فقــط القراءة هي التى تجعلك تشعـــر انك لم تعش حياة قصيــرة ، بل عِشــت مئات السنيـــن !

 *************************** Continue Reading →

Next Page