Created
February 12, 2015 18:22
-
-
Save lily-mara/e84c14966384c428a3d8 to your computer and use it in GitHub Desktop.
Zero-Cost Abstraction
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
class Sum(object): | |
def __init__(self): | |
self._sum = 0 | |
def increment(self, val): | |
self._sum += val | |
def print_sum(self): | |
print self._sum | |
s = Sum() | |
for i in range(1, 1000001): | |
s.increment(i) | |
s.print_sum() |
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
sum = 0 | |
for i in range(1, 1000001): | |
sum += i | |
print sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment