Compare the performance of C, Java, go recursive computing Fibonacci (40)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Fibonacci.c#include <stdio.h>int Main () {printf ("%d", Fibonacci (40));}        int Fibonacci (int n) {if (n < 2) {return 1; } return Fibonacci (n-2) + Fibonacci (n-1);}

Compiling: cflags= "-march=corei7-avx-o2-pipe" && gcc fibonacci.c

Run: Time./a.out

Results: 165580141
          real    0m0.977s
          user    0m0.975s
           sys    0m0.002s

 Fibonacci.javapublic class Fibonacci {         Public static void main (String[] args)  {                 system.out.println (Fibonacci (+));         }        public static int  fibonacci (int n)  {                 if  (n < 2)  {                         return 1;                 }                 return fibonacci (n &NBSP;-&NBSP;2)  + fibonACCI (n - 1);         }} 

Compilation: Javac Fibonacci.java

Run: Time Java Fibonacci

Results: 165580141
Real 0m0.681s
User 0m0.671s
SYS 0m0.016s

Fibonacci.gopackage mainimport "FMT" func Fibonacci (n int) int {if (n < 2) {return 1} Return Fibonacci (N-2) + Fibonacci (n-1)}func main () {FMT. Println (Fibonacci (40))}

Compiling: Go build fibonacci.go

Run: Time./fibonacci

Results: 165580141
Real 0m1.175s
User 0m1.173s
SYS 0m0.004s


From the results: Performance java > C > Go a little weird huh.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.