ds-algo-course

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" "time" ) func main() { // nemo := []string{"nemo"} // everyone := []string{"dory", "bruce", "marlin", "nemo", "gill", "bloat", "nigel", "squirt", "darla", "hank"} large := make([]string, 100000) for i := range large { large[i] = "nemo" } findNemo(large) } func findNemo(array []string) { start := time.Now() for i := 0; i < len(array); i++ { if array[i] == "nemo" { fmt.Println("Found NEMO!") } } elapsed := time.Since(start) fmt.Printf("\nCall to find Nemo took %+v\n", elapsed) } // func formatElapsedTime(d time.Duration) string { // switch { // case d < time.Microsecond: // return fmt.Sprintf("%d ns", d.Nanoseconds()) // case d < time.Millisecond: // return fmt.Sprintf("%d µs", d.Microseconds()) // case d < time.Second: // return fmt.Sprintf("%d ms", d.Milliseconds()) // case d < time.Minute: // return fmt.Sprintf("%.3f sec", d.Seconds()) // case d < time.Hour: // return fmt.Sprintf("%.3f min", d.Minutes()) // default: // return fmt.Sprintf("%.3f hr", d.Hours()) // } // }
Editor Settings
Theme
Key bindings
Full width
Lines