2012-06-14 54 views
7

我運行在Ubuntu的腳本,並測試其時間:爲什麼在cygwin這麼慢

$ 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的執行速度?

+2

與Linux相比,Windows上的產卵過程非常緩慢 - cygwin可以做的很多事情來解決這個限制。 –

+0

檢查是否[此](http://stackoverflow.com/questions/2835775/msysgit-bash-is-horrendously-slow-in-windows-7)有幫助。 –

+0

@PaulR,但我不認爲這會導致3分鐘的滯後。我認爲當OP嘗試這些時,還有其他進程在Windows中運行。或者他在程序中使用了Windows和Linux中顯着不同的東西。 –

回答

1

正如其他人已經提到的,在Windows上fork和進程產卵的Cygwin's implementation一般都很慢。

使用this fork() benchmark,我得到以下結果:

[email protected]:~$ ./test 1000 
Forked, executed and destroyed 1000 processes in 5.660011 seconds. 

[email protected]:~$ ./test 1000 
Forked, executed and destroyed 1000 processes in 0.142595 seconds. 

[email protected]:~$ ./test 1000 
Forked, executed and destroyed 1000 processes in 1.141982 seconds. 

使用time (for i in {1..10000};do cat /dev/null;done)到基準過程產卵的表現,我得到以下結果:

[email protected]:~$ time (for i in {1..10000};do cat /dev/null;done) 
(...) 19.11s user 38.13s system 87% cpu 1:05.48 total 

[email protected]:~$ time (for i in {1..10000};do cat /dev/null;done) 
(...) 0.06s user 0.56s system 18% cpu 3.407 total 

[email protected]:~$ time (for i in {1..10000};do cat /dev/null;done) 
(...) 0.51s user 4.98s system 21% cpu 25.354 total 

硬件規格:

  • 的cygwinIntel(R) Core(TM) i7-3770K CPU @ 3.50GHz
  • Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  • Debian的Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz

所以你看,不管你用什麼不同,Cygwin會一直工作雪上加霜。它甚至損失了手,甚至更糟糕的硬件(cygwindebian在這個基準,根據this comparison)。