PHP 7.3.8-1+0
20190807.43+debian91.gbp7731bf (cli) (built: Aug 7 2019 19:46:25) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.8-1+020190807.43+debian91.gbp7731bf, Copyright (c) 1999-2018, by Zend Technologies
Doesn't need compilation
$ time php fibonacci.php
<?php
/**
* Calculo fibonacci até 1 milhão
*/
$fibonacci = 1;
$last1 = 0;
$last2 = 1;
for ($i=0; $i < 1000000; $i++) {
$fibonacci = $last1 + $last2;
$last1 = $last2;
$last2 = $fibonacci;
}
print("The End\n");
OUTPUT:
The End
real 0m0,050s
user 0m0,036s
sys 0m0,012s
openjdk 11.0.4 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)
$ javac Fibonacci.java
$ time java Fibonacci
public class Fibonacci {
public static void main(String[] args) {
int fibonacci = 1;
int last1 = 0;
int last2 = 1;
for (int i=0; i < 1000000; i++) {
fibonacci = last1 + last2;
last1 = last2;
last2 = fibonacci;
}
System.out.println("The End");
}
}
OUTPUT:
The End
real 0m0,070s
user 0m0,081s
sys 0m0,020s
gcc (Debian 8.3.0-6) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc.
$ gcc -o fibonacciC fibonacci.c
$ time ./fibonacciC
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int fibonacci = 1;
int last1 = 0;
int last2 = 1;
for (int i=0; i < 1000000; i++) {
fibonacci = last1 + last2;
last1 = last2;
last2 = fibonacci;
}
printf("The End\n");
return 0;
}
OUTPUT:
The End
real 0m0,009s
user 0m0,009s
sys 0m0,000s
g++ (Debian 8.3.0-6) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc.
$ g++ -o fibonacciCPP fibonacci.cpp
$ time ./fibonacciCPP
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv) {
int fibonacci = 1;
int last1 = 0;
int last2 = 1;
for (int i=0; i < 1000000; i++) {
fibonacci = last1 + last2;
last1 = last2;
last2 = fibonacci;
}
printf("The End\n");
return 0;
}
OUTPUT:
The End
real 0m0,010s
user 0m0,010s
sys 0m0,000s
Python 2.7.16
$ python2 -m py_compile fibonacci.py
$ time python2 fibonacci.pyc
fibonacci = 1
last1 = 0
last2 = 1
theRange = 1000000
for i in range(theRange):
fibonacci = last1 + last2
last1 = last2
last2 = fibonacci
print("The End\n")
OUTPUT:
The End
real 0m12,476s
user 0m12,434s
sys 0m0,040s
Python 3.7.3
Does not work with
py_compile
. Got an error: 'RuntimeError: Bad magic number in .pyc file'
$ time python3 fibonacci.py
Same code as Python2
fibonacci = 1
last1 = 0
last2 = 1
theRange = 1000000
for i in range(theRange):
fibonacci = last1 + last2
last1 = last2
last2 = fibonacci
print("The End\n")
OUTPUT:
The End
real 0m12,752s
user 0m12,704s
sys 0m0,048s
Dart VM version: 2.4.1 (Unknown timestamp) on "linux_x64"
Compiled with
dart2aot
$ dart2aot Fibonacci.dart Fibonacci.aot
$ time ./dartaotruntime Fibonacci.aot
void main(List<String> args) {
int fibonacci = 1;
int last1 = 0;
int last2 = 1;
for (int i=0; i < 1000000; i++) {
fibonacci = last1 + last2;
last1 = last2;
last2 = fibonacci;
}
print('The End');
}
OUTPUT:
The End
real 0m0,019s
user 0m0,016s
sys 0m0,004s
_,met$$$$$gg. prescott@PeDePano
,g$$$$$$$$$$$$$$$P. OS: Debian 10 buster
,g$$P"" """Y$$.". Kernel: x86_64 Linux 4.19.0-5-amd64
,$$P' `$$$. Uptime: 2h 37m
',$$P ,ggs. `$$b: Packages: 3528
`d$$' ,$P"' . $$$ Shell: bash
$$P d$' , $$P Resolution: 1600x900
$$: $$. - ,d$$' DE: GNOME
$$\; Y$b._ _,d$P' WM: GNOME Shell
Y$$. `.`"Y$$$$P"' WM Theme:
`$$b "-.__ GTK Theme: Adwaita [GTK2/3]
`Y$$ Icon Theme: Adwaita
`Y$$. Font: Cantarell 11
`$$b. CPU: Intel Core i3-2100 @ 4x 3.1GHz [37.0°C]
`Y$$b. GPU: Mesa DRI Intel(R) Sandybridge Desktop
`"Y$b._ RAM: 4181MiB / 7823MiB
`""""
Thank you guys for contributing. Fibonacci calc well done is the first example in the https://www.python.org page. I didn't realize that when did that vídeo and all this tests.
However this tests should not be took so serious because execution speed is not so important when we talk about all benefits a language can give us. Python, as other languages here and that ones which are not, is a great tool.