%%time
import scanpy as sc
import matplotlib.pyplot as plt
from time import time
## test time
filename="./1M_neurons_neuron20k.h5"
x0=time()
adata = sc.read_10x_h5(filename)
print(adata)
x1=time()
print("read done..............cost {}s".format(round(x1-x0)))
sc.pp.recipe_zheng17(adata)
x2=time()
print("preprocess.............cost {}s".format(round(x2-x1)))
sc.pp.neighbors(adata)
x3=time()
print("cal neighbors..........cost {}s".format(round(x3-x2)))
sc.tl.louvain(adata)
x4=time()
print("louvain done ..........cost {}s".format(round(x4-x3)))
sc.tl.umap(adata)
x5=time()
print("cal umap done..........cost {}s".format(round(x5-x4)))
sc.pl.umap(adata,color="louvain",show=False)
x6=time()
print("plot umap done.........cost {}s".format(round(x6-x5)))
plt.savefig("./20k_louvain.png")
x7=time()
print("all done.........total cost {}s".format(round(x7-x0)))
结果如下
记录一下
内存使用
如果同时测试时间和内存,方式如下
其中有monitor_time_linux.sh
echo -e "Runtime(s)\tMemoryUse"
SECONDS=0
while [ 1 ]; do
## Get the PID of the process name given as argument 1
#specify PID
pidno=$1
## If the process is running, print the memory usage
sleep 1
#on ubuntu/centos
if [ -e /proc/$pidno/statm ]; then
## Get the memory info,on ubunt
#m=`awk '{OFS="\t";print $1, $2,$3,$6}' /proc/$pidno/statm`
## Get the memory percentage
#perc=`top -bd .10 -p $pidno -n 1 | grep $pidno | awk '{OFS="\t";print $6,$10}'`# $10 is percentage
perc=`top -bd .10 -p $pidno -n 1 | grep $pidno | awk '{OFS="\t";print $6}'`
else
echo "# $1 is not running";
break;
fi
echo -e "$SECONDS\t$perc";
done
那么使用的方式如下,首先写好自己的测试.py文件(mousebrain_20k_cluster.py)
import scanpy as sc
import matplotlib.pyplot as plt
from time import time
## test time
filename="./1M_neurons_neuron20k.h5"
x0=time()
adata = sc.read_10x_h5(filename)
print(adata)
x1=time()
print("read done..............cost {}s".format(round(x1-x0)))
sc.pp.recipe_zheng17(adata)
x2=time()
print("preprocess.............cost {}s".format(round(x2-x1)))
sc.pp.neighbors(adata)
x3=time()
print("cal neighbors..........cost {}s".format(round(x3-x2)))
sc.tl.louvain(adata)
x4=time()
print("louvain done ..........cost {}s".format(round(x4-x3)))
sc.tl.umap(adata)
x5=time()
print("cal umap done..........cost {}s".format(round(x5-x4)))
sc.pl.umap(adata,color="louvain",show=False)
x6=time()
print("plot umap done.........cost {}s".format(round(x6-x5)))
plt.savefig("./20k_louvain.png")
x7=time()
print("all done.........total cost {}s".format(round(x7-x0)))
那么在服务器上就可以运行以下命令就可以了
nohup python -u mousebrain_20k_cluster.py >log_20k.txt 2>&1 &
nohup bash monitor_time_linux.sh $! > runtime_20k.txt 2>&1 &
(加回车)
等程序运行完就可以了