diff --git a/racer/racer.go b/racer/racer.go new file mode 100644 index 0000000..8927c2e --- /dev/null +++ b/racer/racer.go @@ -0,0 +1,23 @@ +package racer + +import ( + "fmt" + "net/http" + "time" +) + +func Racer(a, b string) string { + startA := time.Now() + http.Get(a) + aDuration := time.Since(startA) + fmt.Println(aDuration) + + startB := time.Now() + http.Get(b) + bDuration := time.Since(startB) + fmt.Println(bDuration) + if aDuration < bDuration { + return a + } + return b +} diff --git a/racer/racer_test.go b/racer/racer_test.go new file mode 100644 index 0000000..691bfb0 --- /dev/null +++ b/racer/racer_test.go @@ -0,0 +1,15 @@ +package racer + +import "testing" + +func TestRacer(t *testing.T) { + slowURL := "http://www.facebook.com" + fastURL := "http://www.quii.dev" + + want := fastURL + got := Racer(slowURL, fastURL) + + if got != want { + t.Errorf("got %q, want %q", got, want) + } +}