我在 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的执行速度?
正如其他人已经提到的,Cygwin在 Windows 上的 fork 和进程生成的实现通常很慢。
使用这个 fork() 基准,我得到以下结果:
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 总是会运行得更糟。cygwin
它甚至对更差的硬件(与debian
此基准相比,根据此比较)失去了手感。