Skip to content

Latest commit

 

History

History
108 lines (75 loc) · 2.93 KB

File metadata and controls

108 lines (75 loc) · 2.93 KB

Fibo Matrix

Rust Command Line tool that calculates the n'th fibonacci number.

Created by Luca

Bench

Method chosen is fastest for that N, that calculates the correct answer. (Approximations / Non-bigint-implementations do not always return the correct result, due to the nature of approximation and due to overflowing integers)

N time method
100 40ns 4
1000 3.66us 0
10K 15.25us 0
100K 318us 0
1M 3.06ms 8
10M 33.73ms 8
100M 547ms 8
1B 5.78s 8

Note: Experimental method 15 (Rayon matrix multiplication 5) often outperforms method 8 by ~1.8-2x for medium to large N due to reduced temporary allocations and in-place reuse; benchmarks table will be updated after broader validation.

Usage

Build using cargo build --release or run cargo run --release -- $ where $ is to be replaced with command-line arguments.

Note

The first compile could take multiple minutes as 'gmp-mpfr-sys' is building. It is not frozen!

Example

cargo build --release
target/release/fastest-fibo -m 8 --length 100000000 --quiet

or

cargo run --release -- -m 8 --length 100000000 --quiet --warmup 10

or

Usage: fibomatrix [OPTIONS] --length <LENGTH>

Options:
  -l, --length <LENGTH>
          Length of the Fibonacci sequence to generate
          
          This is the number of Fibonacci numbers to generate
          
          The minimum is 1

  -m, --method <METHOD>
          Method to use 
          
          
          Options: 
           
           Single-threaded: 
           > 0: Single-threaded matrix multiplication 
           > 1: Iterative 
           > 2: Recursive 
           > 3: Recursive with memoization 
           > 4: Single-threaded matrix multiplication without BigInt 
           
           Rayon (each variant is more optimized than the last): 
           > 5: Rayon matrix multiplication 1 
           > 6: Rayon matrix multiplication 2 
           > 7: Rayon matrix multiplication 3 
           > 8: Rayon matrix multiplication 4 
           > 15: Rayon matrix multiplication 5 (in-place optimized) 
           
           Threads: 
           > 9: Threads matrix multiplication 1 (WIP) 
           
           Approximation (BigFloat): 
           > 10: Approximation 1 
          
          
          [default: 1]

  -q, --quiet
          Don't print the result 
           (large numbers can take a long time to print, so this can save a lot of time)
          
          [default: false]

  -n, --no-time
          Don't print the time elapsed
          
          [default: false]

  -p, --precision <PRECISION>
          Precision for approximation
          
          [default: 100]

  -w, --warmup <WARMUP>
          Warmup iterations (number of times to run the calculation before timing it)
          
          [default: 0]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version