PHP_IloveU (2) php food and clothing parents: Java and PHP efficiency competition: PHP_ I love U (1) php food and clothing parents: Java and PHP efficiency competition:
Fibonacci series
Fibonacci
See: http://zh.wikipedia.org/wiki/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97
(It should be 1. the Wikipedia formula is incorrect !?!)
(N? 2)
Write the Java code first this time:
Class fb {
Static int f1b (int x ){
If (0 = x) | (1 = x) {return 1 ;}
Int;
A = f1b (x-1) + x;
System. out. println ();
Return;
}
Public static void main (String [] args ){
Long startTime = System. nanoTime (); // star
Long startTimeMs = System. currentTimeMillis ();//
// DoSomeThing (); // Coding
F1b (999 );
Long endTime = System. nanoTime (); // end
System. out. println ("Run Timming:" + (endTime-startTime) + "ns ");
Long endTimeMs = System. currentTimeMillis (); // get the end time
System. out. println ("Runing Time:" + (endTimeMs-startTimeMs) + "ms ");
} // Main
} // Class fb
PHP code:
Function Fun1 ($ x) // $ x)
{
If (0 === x) {return 1; echo "\ r \ n ";}
If (1 === x) {return 1; echo "\ r \ n ";}
$ B1 = $ x + Fun1 ($ X-1 );
Echo $ b1;
Echo "\ r \ n ";
Return $ b1;
}
$ X0 = 999; // 100;
$ T1 = microtime (true );
// Code for testing (time) efficiency;
Fun1 ($ x0 );
$ T2 = microtime (true );
Echo ($ t2-$ t1) * 1000). 'Ms ';
Result:
Java :......
499500
Time: 102.167238ns
Ms time: 104 ms
PHP :...
......
499500
Time (ms): 161.00978851318 ms
Result:
JAVA vs PHP
104 ms vs 161 ms
1574 ms vs 909 ms
Of course, Java won ......
But considering that java code should be compiled with Javac ......
PHP code runs directly with php.exe.
So after the calculation of the 999 (or 9999) Fibonacci series (both approximate) 1: 1.6 Efficiency ratio ...... PHP is acceptable.
In short: php I continues to love U (you )!