Last active
December 19, 2017 16:27
-
-
Save Mossuru777/52db657a35207af49ea6aa42b7ab02e1 to your computer and use it in GitHub Desktop.
Numpy vs Cupy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cupy==1.0.0b1 | |
numpy==1.11.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be great if you post the results as well! Thanks :)