Files
talks/concurrency/cmd/temperatures/main.go
T

41 lines
517 B
Go
Raw Normal View History

2020-05-31 21:09:26 +00:00
package main
import (
"fmt"
"time"
)
var cities = []string{
"Chicago",
"Dallas",
"Houston",
"Los Angeles",
"New York",
"Philadelphia",
"Phoenix",
"San Antonio",
"San Diego",
"San Jose",
}
func main() {
now := time.Now()
printTemperatures(cities)
fmt.Printf(
"\nTook %v to get temperatures sequentially.\n\n",
time.Since(now),
)
// Reset the timer.
now = time.Now()
printTemperaturesAsync(cities)
fmt.Printf(
"\nTook %v to get temperatures concurrently.\n\n",
time.Since(now),
)
}