import time
import numpy as np
import random
defdotting(a, b):
return a.dot(b)
deflooping(a, b):
D = len(a)
result = 0for i inrange(D):
result += a[i]*b[i]
return result
if __name__ == '__main__':
dim = 100_000_000
a = [random.random() for _ inrange(dim)]
b = [random.random() for _ inrange(dim)]
start_time = time.time()
looping(a, b)
print("looping takes: " + str(time.time()-start_time))
a = np.array(a)
b = np.array(b)
start_time = time.time()
dotting(a, b)
print("dotting takes: " + str(time.time()-start_time))
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (15/15), done.
Connection to github.com closed by remote host.
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedlyやその上のメッセージなどでググったら「configでBufferのサイズを変えてみたら?」とか出たのでやってみたがうまくいかなかった
# xargsの挙動
## 外部コマンドの存在するwhichの場合
$ type -a which
which is /usr/bin/which
which is /bin/which
$ echo 'ls' | xargs -I@ which ls
/usr/bin/which # whichは発動している
## 外部コマンドが存在しないtypeの場合
$ type -a type
type is a shell builtin # ビルドインコマンドしか存在しない
$ echo 'ls' | xargs -I@ type ls
xargs: type: No such file or directory
# echoの挙動
$ type echo
echo is a shell builtin
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
## ビルドインコマンド(通常)
$ echo -e '\uFF10'
0
## 外部コマンド
$ /usr/bin/echo -e '\uFF10'
\uFF10
補足
whichとtype
whichとtypeは挙動が似ているが、この違いもビルドインコマンドか外部コマンドかで説明できる
typeの方がビルドインコマンドである分、より正確に実行されるコマンドを把握している
$ type echo
echo is a shell builtin
$ which echo
/usr/bin/echo