Write a Python program to optimize the following code snippet so that it runs faster
n = 10
arr = []
for i in range(n):
  arr.append(i * i)
print(arr)
def optimizeCode():
  n = 10
  arr = [i * i for i in range(n)]
  print(arr)

optimizeCode()