Skip to content

Instantly share code, notes, and snippets.

@zachad
Created May 6, 2014 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachad/00f8b31000d614383d0f to your computer and use it in GitHub Desktop.
Save zachad/00f8b31000d614383d0f to your computer and use it in GitHub Desktop.
Added benchmarks to the scrabble_score exercism test.
package scrabble_score
import "testing"
var tests = []struct {
input string
expected int
}{
{"", 0},
{" \t\n", 0},
{"a", 1},
{"f", 4},
{"street", 6},
{"quirky", 22},
{"MULTIBILLIONAIRE", 20},
{"alacrity", 13},
}
func TestScore(t *testing.T) {
for _, test := range tests {
if actual := Score(test.input); actual != test.expected {
t.Errorf("Score(%q) expected %d, Actual %d", test.input, test.expected, actual)
}
}
}
func BenchmarkScore(b *testing.B) {
for n := 0; n < b.N; n++ {
Score("quirkymuffin")
}
}
func BenchmarkScoreUnicode(b *testing.B) {
for n := 0; n < b.N; n++ {
ScoreUnicode("quirkymuffin")
}
}
@zachad
Copy link
Author

zachad commented May 6, 2014

On my machine:

❯ go test -bench=.
PASS
BenchmarkScore   5000000           330 ns/op
BenchmarkScoreUnicode   10000000           247 ns/op
ok      _/Users/zachad/Projects/exercism/go/scrabble-score  4.719s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment