Dear friend 3702, while you are at it, please change that string appending 
strategy. Use a bufio.Buffer instead. It's way faster.


> type bad.go
package main

import (
        "fmt"
        "time"
)

func main() {
        var s string
        begin := time.Now()
        for i := 0; i != 100000; i++ {
                s = s + "lalalala"
        }
        fmt.Printf("len = %d, %d ns\n", len(s), 
time.Now().UnixNano()-begin.UnixNano())
}

> bad.exe
len = 800000, 3573571400 ns

> bad.exe
len = 800000, 3564547900 ns

> bad.exe
len = 800000, 3657745100 ns

> type good.go
package main

import (
        "bytes"
        "fmt"
        "io"
        "time"
)

func main() {
        var b bytes.Buffer
        begin := time.Now()
        for i := 0; i != 100000; i++ {
                io.WriteString(&b, "lalalala")
        }
        s := b.String()
        fmt.Printf("len = %d, %d secs\n", len(s), 
time.Now().UnixNano()-begin.UnixNano())
}

> good.exe
len = 800000, 2991600 secs

> good.exe
len = 800000, 4002600 secs

> good.exe
len = 800000, 3001800 secs


-- 
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