我在Ubuntu上运行一个脚本,并测试了它的时间:
$ time ./merger
./merger 0.02s user 0.03s system 99% cpu 0.050 total
它花了不到1秒钟。
但如果我用cygwin:
$ time ./merger
real 3m22.407s
user 0m0.367s
sys 0m0.354s
花了超过3分钟。 为什么会这样?我该怎么做才能提高cygwin的执行速度?
答案 0 :(得分:2)
正如其他人已经提到的,Windows上的fork和进程产生的Cygwin's implementation通常很慢。
使用this fork() benchmark,我得到以下结果:
rr-@cygwin:~$ ./test 1000
Forked, executed and destroyed 1000 processes in 5.660011 seconds.
rr-@arch:~$ ./test 1000
Forked, executed and destroyed 1000 processes in 0.142595 seconds.
rr-@debian:~$ ./test 1000
Forked, executed and destroyed 1000 processes in 1.141982 seconds.
使用time (for i in {1..10000};do cat /dev/null;done)
对流程生成性能进行基准测试,得到以下结果:
rr-@work:~$ time (for i in {1..10000};do cat /dev/null;done)
(...) 19.11s user 38.13s system 87% cpu 1:05.48 total
rr-@arch:~$ time (for i in {1..10000};do cat /dev/null;done)
(...) 0.06s user 0.56s system 18% cpu 3.407 total
rr-@debian:~$ time (for i in {1..10000};do cat /dev/null;done)
(...) 0.51s user 4.98s system 21% cpu 25.354 total
硬件规格:
Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz
所以你看,无论你使用什么,Cygwin总是会更糟。根据{{3}}),在此基准测试中,即使硬件更差(cygwin
与debian
,也会丢失。