You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/04 02:17:51 UTC
[GitHub] [incubator-mxnet] wkcn commented on issue #16053: Fixes #15543
wkcn commented on issue #16053: Fixes #15543
URL: https://github.com/apache/incubator-mxnet/pull/16053#issuecomment-527710882
Hi @zhanghang1989 , is there any difference between `a -= b` and `a[:] -= b`?
`a[:] -= b` may call extra function `__getitem__`.
```python
import mxnet as mx
import time
T = 1000
N = 1000
while 1:
ti = time.time()
a = mx.nd.arange(N)
for i in range(T):
a += 1
mx.nd.waitall()
print('a += b: ', time.time() - ti)
ti = time.time()
a = mx.nd.arange(N)
for i in range(T):
a[:] += 1
mx.nd.waitall()
print('a[:] += b: ', time.time() - ti)
```
Output:
```
a += b: 0.06155872344970703
a[:] += b: 0.3492248058319092
a += b: 0.06215381622314453
a[:] += b: 0.30852508544921875
a += b: 0.07872796058654785
a[:] += b: 0.31493425369262695
a += b: 0.08103752136230469
a[:] += b: 0.3226127624511719
a += b: 0.05706977844238281
a[:] += b: 0.29704785346984863
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services