tgpl/ch1/echo/1_3.go

34 lines
457 B
Go
Raw Normal View History

2015-12-03 19:33:19 -08:00
package main
import (
"fmt"
"os"
"strings"
"time"
)
func usingJoin() {
fmt.Println(strings.Join(os.Args[1:], " "))
}
func forLoop() {
s, sep := "", " "
for _, i := range os.Args[1:] {
s += i
s += sep
}
fmt.Println(s)
}
func main() {
start := time.Now()
forLoop()
t1 := time.Since(start)
fmt.Println("for loop: ", t1)
start = time.Now()
usingJoin()
t2 := time.Since(start)
fmt.Println("using join: ", t2)
fmt.Println("Δ", t1-t2)
}