Optimize the following python code to make it run faster.
def sum_of_squares(n):
    s = 0
    for i in range(n):
        s += i * i
    return s
def sum_of_squares(n):
    # Use summation formula to optimize the code
    return (n * (n + 1) * (2 * n + 1)) // 6