package main

import "fmt"
import "testing"

var s string
var a = make([]byte, 1000)

func f0() {
    x := string(a)
    s =     x + x + x + 
        x + x + x + 
        x + x + x + 
        x
}

func f1() {
    s =     string(a) +  string(a) + string(a) +
           string(a) +  string(a) + string(a) +
           string(a) +  string(a) + string(a) +
           string(a)
}

func f2() {
    s =     (" " +
           string(a) +  string(a) + string(a) +
           string(a) +  string(a) + string(a) +
           string(a) +  string(a) + string(a) +
           string(a) )[1:]
}

func main() {
    fmt.Println(testing.AllocsPerRun(1, f0)) // 2
    fmt.Println(testing.AllocsPerRun(1, f1)) // 11
    fmt.Println(testing.AllocsPerRun(1, f2)) // 1
}

why doesn't gc make optimization for f1?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to