Created
May 6, 2014 16:08
-
-
Save zachad/00f8b31000d614383d0f to your computer and use it in GitHub Desktop.
Added benchmarks to the scrabble_score exercism test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my machine: