0

'''

import timeit
import math
x = np.linspace(0,10,20000)
y = np.cos(x)
%timeit y + 1

(0<=x<=10).all()
for i in range(20000):
    y = math.cos(x)
    %timeit y + 1

''' I am getting an error for raw python code. Also i am unable to compute the difference.

Abhilash
  • 11
  • 1
  • Use some good timestamps like these here: https://stackoverflow.com/questions/38319606/how-to-get-millisecond-and-microsecond-resolution-timestamps-in-python/38319607#38319607 – Gabriel Staples Apr 05 '20 at 05:08

1 Answers1

0

How about using time.time()? ( I edited the code)

import numpy as np
import time
import math

# Using Numpy
x = np.linspace(0, 10, 20000)
start_time = time.time()
y = np.sin(x)
end_time = time.time()
print(end_time - start_time)

# using raw
start_time = time.time()
y = []
x = [0, 10]
for i in range(20000 - 2):
    x.insert(1, i * 10 / 20000)

for element in x:
    y.append(math.cos(element))


end_time = time.time()
print(end_time - start_time)
Gilseung Ahn
  • 2,598
  • 1
  • 4
  • 11
  • Thanks Gilseung. But you're using numpy for raw as well. x = np.linspace(0, 10, 20000) is being used in raw as well. – Abhilash Apr 05 '20 at 04:46