Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// print name of calling program,
// list args passed each on a new line,
// print time elapsed
package main
import (
"fmt"
"os"
"strings"
"time"
)
func main() {
start := time.Now()
fmt.Println("binary's name => ", os.Args[0])
// op1
// ---
// s, sep := "", " "
// for i, arg := range os.Args[1:] {
// s = strconv.Itoa(i) + sep + arg
// fmt.Println(s)
// }
// op2
// ---
// (fastest but cant get reference to index ?)
fmt.Println(strings.Join(os.Args[1:], "\n"))
end := time.Now()
elapsed := end.Sub(start)
fmt.Println("time elapsed: " + elapsed.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.