Skip to contents

Time the multithreaded computation of Fibonacci numbers

Usage

fibonacci_omp(n)

Arguments

n

vector giving integers for which to compute the Fibonacci sum

Value

vector of integers giving the Fibonacci sum for each element in n

Details

The function being timed is the following:

int fib(int n) { return ((n <= 1) ? n : fib(n - 1) + fib(n - 2)); }

Runtime for computations less than n = 15 is nearly unmeasurable.

Examples

# \donttest{
fibonacci_omp(n = rep(20:25, 10))
#>  [1]  6765 10946 17711 28657 46368 75025  6765 10946 17711 28657 46368 75025
#> [13]  6765 10946 17711 28657 46368 75025  6765 10946 17711 28657 46368 75025
#> [25]  6765 10946 17711 28657 46368 75025  6765 10946 17711 28657 46368 75025
#> [37]  6765 10946 17711 28657 46368 75025  6765 10946 17711 28657 46368 75025
#> [49]  6765 10946 17711 28657 46368 75025  6765 10946 17711 28657 46368 75025
# this function creates a global environment variable "times"
times
#>          Microseconds     SD      Min      Max Count
#> fib_20         38.322 16.904   26.861   71.144    10
#> fib_21         39.755  4.381   35.678   45.175    10
#> fib_22         78.940  8.061   69.440   87.244    10
#> fib_23        110.504 19.146   93.386  155.893    10
#> fib_24        194.637 18.809  172.004  215.726    10
#> fib_25        271.736 39.912  232.568  323.710    10
#> fib_body     2442.588  0.000 2442.588 2442.588     1
# }