High Performance Calculation of Sums and Returns in Go I am writing a finance library with the intention to have the best of Golang's performance. 

The function Re calculates the returns of a float list, and function Sum calculates the sum of float list.

//Calculate returns
func Re(data []float64) []float64 {

    re_ := make([]float64, len(data))
    for i := 1; i &lt; len(data); i++ {
        re_[i] = ( (data[i]/data[i-1])-1)
    }

    return re_
}

// sum of float64 list
func Sum(floatList []float64) float64 {

    var totalx float64
    for _, valuex := range floatList {
        totalx += valuex
    }

    return totalx
}


is there any further possible optimisation on these two functions or another more performant way to write them?
In Go, when you want to measure function performance, use the Go testing package to run a benchmark.

For example,

returns.go:

package finance

// Calculate returns
func Re(data []float64) []float64 {
    var re []float64
    if len(data) &gt; 0 {
        re = make([]float64, len(data))
    }
    for i := 1; i &lt; len(data); i++ {
        if data[i-1] != 0 {
            re[i] = (data[i] / data[i-1]) - 1
        }
    }
    return re
}

// Calculate sum
func Sum(data []float64) float64 {
    var sum float64
    for _, x := range data {
        sum += x
    }
    return sum
}


returns_test.go:

package finance

import "testing"

func BenchmarkRe(b *testing.B) {
    data := make([]float64, 5*12)
    for i := range data {
        data[i] = float64(i)
    }
    b.ResetTimer()
    for N := 0; N &lt; b.N; N++ {
        Re(data)
    }
}

func BenchmarkSum(b *testing.B) {
    data := make([]float64, 5*12)
    for i := range data {
        data[i] = float64(i)
    }
    b.ResetTimer()
    for N := 0; N &lt; b.N; N++ {
        Sum(data)
    }
}


Output:

$ go test returns.go returns_test.go -bench=. -benchmem
BenchmarkRe-4     7545566   156 ns/op     480 B/op    1 allocs/op
BenchmarkSum-4   28272992    41.5 ns/op     0 B/op    0 allocs/op
$


I looked at some other alternatives, but that's the fastest.

Note: I fixed your divide-by-zero bug.