34 lines
457 B
Go
34 lines
457 B
Go
|
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)
|
||
|
}
|