#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'teng'

import sys
from datetime import datetime
import numpy as np

"""
演示numpy速度
"""

# 两个numpy数组相加
def numpysum(n):
    a = np.arange(n)**2
    b = np.arange(n)**3
    c = a+b
    return c

# 两个列表相加
def pythonsum(n):
    a = range(n)
    b = range(n)
    c = []
    for i in range(len(a)):
        a[i] = i ** 2
        b[i] = i ** 3
        c.append(a[i]+b[i])
    return c
size = int(sys.argv[1])
start = datetime.now()
c = pythonsum(size)
delta = datetime.now()-start
print "The last 2 elements of the sum", c[-2:]
print "PythonSum elapsed time in microseconds", delta.microseconds
start = datetime.now()
c = numpysum(size)
delta = datetime.now() - start
print "The last 2 elements of the sum", c[-2:]
print "NumPySum elapsed time in microseconds", delta.microseconds