My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Comparison: Node.js, PHP, C, Go, Python and Ruby

Deactivated User's photo
Deactivated User
·May 11, 2016

I had fun doing performance tests after reading an article which had performance tests for Python.

I wanted to only test web back-end tech, but I still added in a test with C in order to compare everythig else with a low-level language.

Here is the code:

Python

sum = 0
for i in range(100000000):
    sum += i
print(sum)

Ruby

#!/usr/bin/ruby

$sum = 0
for $i in 0..100000000
      $sum += $i
end
puts($sum)

Node.js

#!/usr/bin/env

var sum = 0
for (var i = 0; i < 100000000; i++) {
    sum +=i
}
console.log(sum);

PHP

#!/usr/bin/php
<?php
$sum = 0;
for ($i = 1; $i < 100000000; $i++) {$sum += $i;}    echo $sum + '\n'?>

Go

package main

import "fmt"

func main() {
    sum := 0
    for i := 0; i < 100000000; i++ {
        sum += i
    }
    fmt.Println(sum)
}

C

#include <stdio.h>

int main ()
{
  int a;
  int sum = 0;
  for( a = 0; a < 100000000; a++ )
    {
      sum += a;
    }
  printf("sum: %d\n", sum);
  return 0;
}

Results:

Result

And the winner is... GO !

PS : Go here is 9x better than than C, but with good optimisation flags, C is faster.