Last active
          February 24, 2025 08:54 
        
      - 
      
- 
        Save miguelgrinberg/e5613bbd42354c7eb4eb1c2a4be2f018 to your computer and use it in GitHub Desktop. 
    Fibonacci benchmark
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const fibo = n => { | |
| if (n <= 1) { | |
| return n; | |
| } | |
| else { | |
| return fibo(n-1) + fibo(n-2); | |
| } | |
| } | |
| for (let n of process.argv.slice(2)) { | |
| console.log(`fibo(${n}) = ${fibo(n)}`); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import sys | |
| def fibo(n): | |
| if n <= 1: | |
| return n | |
| else: | |
| return fibo(n-1) + fibo(n-2) | |
| if __name__ == '__main__': | |
| for n in sys.argv[1:]: | |
| print(n, fibo(int(n))) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | use std::env; | |
| pub fn fibo(n: u32) -> u32 { | |
| match n { | |
| 0 => 0, | |
| 1 => 1, | |
| _ => fibo(n - 1) + fibo(n - 2), | |
| } | |
| } | |
| pub fn main() { | |
| let args: Vec<String> = env::args().skip(1).collect(); | |
| for arg in args.iter() { | |
| let n: u32 = arg.parse().unwrap(); | |
| println!("fibo({}) = {}", n, fibo(n)); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment