Skip to content

Inconsistent example about Fibonacci benchmarks #13

@nawa

Description

@nawa

There is something wrong with the story about Fibonacci benchmarks presented in the compiled view here https://dave.cheney.net/high-performance-go-workshop/dotgo-paris.htm

First, you have the example of an unoptimized Fibonacci algorithm

func Fib(n int) int {
	switch n {
	case 0:
		return 0
	case 1:
		return 1
	case 2:
		return 2
	default:
		return Fib(n-1) + Fib(n-2)
	}
}

Despite it is wrong and provides incorrect result maybe it's made intentionally. But then you have a slightly optimized version on the paragraph 2.3.1. Improve Fib

func Fib(n int) int {
	switch n {
	case 0:
		return 0
	case 1:
		return 1
	case 2:
		return 1
	default:
		return Fib(n-1) + Fib(n-2)
	}
}

It's a correct working version of the algorithm but they are equal from the performance point of view, so the point about some optimization looks strange

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions