You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
348 B
Go
24 lines
348 B
Go
5 months ago
|
package my_select
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func Racer(a string, b string) (winner string) {
|
||
|
aDuration := measureResponseTime(a)
|
||
|
bDuration := measureResponseTime(b)
|
||
|
|
||
|
if aDuration < bDuration {
|
||
|
return a
|
||
|
}
|
||
|
|
||
|
return b
|
||
|
}
|
||
|
|
||
|
func measureResponseTime(url string) time.Duration {
|
||
|
start := time.Now()
|
||
|
http.Get(url)
|
||
|
return time.Since(start)
|
||
|
}
|