Commit 5c49c84

mo khan <mo.khan@gmail.com>
2019-10-23 02:07:28
https://github.com/quii/learn-go-with-tests/blob/master/iteration.md#benchmarking
1 parent 6e627fd
bin/benchmark
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+go test -bench=.
repeat.go
@@ -3,7 +3,7 @@ package main
 func Repeat(character string) string {
   var repeated string
   for i := 0; i < 5; i++ {
-    repeated = repeated + character
+    repeated += character
   }
   return repeated
 }
repeat_test.go
@@ -10,3 +10,9 @@ func TestRepeat(t *testing.T) {
     t.Errorf("expected %q but got %q", expected, repeated)
   }
 }
+
+func BenchmarkRepeat(b *testing.B) {
+  for i := 0; i < b.N; i++ {
+    Repeat("a")
+  }
+}