from time import clock

def test_return(n):
    def f(x):
        if x % 2:
            return None
        return x
    s = 0
    for x in xrange(n):
        r = f(x)
        if r is not None:
            s += r
    return s

def test_except(n):
    def f(x):
        if x % 2:
            raise StopIteration()
        return x
    s = 0
    for x in xrange(n):
        try:
            s += f(x)
        except StopIteration:
            pass
    return s

N = 1000000

t = clock()
print test_return(N)
print 'Return: ', clock() - t

t = clock()
print test_except(N)
print 'Raise: ', clock() - t