相关疑难解决方法(0)

我的脚本有问题还是 Bash 比 Python 慢得多?

我通过运行 10 亿次循环来测试 Bash 和 Python 的速度。

$ cat python.py
#!/bin/python
# python v3.5
i=0;
while i<=1000000000:
    i=i+1;
Run Code Online (Sandbox Code Playgroud)

重击代码:

$ cat bash2.sh
#!/bin/bash
# bash v4.3
i=0
while [[ $i -le 1000000000 ]]
do
let i++
done
Run Code Online (Sandbox Code Playgroud)

使用该time命令,我发现 Python 代码只需要 48 秒即可完成,而 Bash 代码在我杀死脚本之前需要 1 个多小时。

为什么会这样?我预计 Bash 会更快。我的脚本有问题还是 Bash 使用这个脚本真的慢得多?

bash python3

32
推荐指数
5
解决办法
1万
查看次数

标签 统计

bash ×1

python3 ×1