Skip to content

Instantly share code, notes, and snippets.

@Mossuru777
Last active December 19, 2017 16:27
Show Gist options
  • Save Mossuru777/52db657a35207af49ea6aa42b7ab02e1 to your computer and use it in GitHub Desktop.
Save Mossuru777/52db657a35207af49ea6aa42b7ab02e1 to your computer and use it in GitHub Desktop.
Numpy vs Cupy
import cupy
import numpy
import time
cupy.cuda.set_allocator(cupy.cuda.MemoryPool().malloc)
n = numpy.random.rand(1000, 1000)
c = cupy.array(numpy.random.rand(1000, 1000))
n_add = numpy.random.rand(1000, 1000)
c_add = cupy.array(numpy.random.rand(1000, 1000))
TRY = 10000
# numpy
starttime = time.time()
for i in range(TRY):
n + n_add
endtime = time.time()
n_interval = endtime - starttime
print("CPU: {}".format(n_interval))
# cupy
starttime = time.time()
for i in range(TRY):
c + c_add
endtime = time.time()
c_interval = endtime - starttime
print("GPU: {}".format(c_interval))
cupy==1.0.0b1
numpy==1.11.3
@several27
Copy link

Would be great if you post the results as well! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment