Recently, I was working on making a scrabble game point tracker and started to wonder how much of a difference moving small things like a function makes to the performance of code.
I have an example here of what I mean if what I said above didn’t make much sense.
Which is better for performance:
def score_word(word):
point_total = 0
for letter in word.upper():
point_total += letter_to_points.get(letter, 0)
return point_total
Where I put .upper() after word in the third line,
def score_word(word):
point_total = 0
for letter in word:
point_total += letter_to_points.get(letter.upper(), 0)
return point_total
Or where .upper() is after letter in the fourth line?
I tried testing which was better on a larger scale, but I still couldn’t tell a performance difference.
3