8

I run a script on Ubuntu, and tested its time:

$ time ./merger
./merger  0.02s user 0.03s system 99% cpu 0.050 total

it spent less than 1 second. but if I used cygwin:

$ time ./merger
real    3m22.407s
user    0m0.367s
sys     0m0.354s

It spent more than 3 minutes. Why did this happen? What shall I do to increase the executing speed on cygwin?

Zombo
  • 1
  • 62
  • 391
  • 407
vv1133
  • 739
  • 1
  • 8
  • 21
  • 2
    Spawning processes on Windows is very slow compared to Linux - there is not much that cygwin can do to get around this limitation. – Paul R Jun 14 '12 at 11:33
  • Check if [this](http://stackoverflow.com/questions/2835775/msysgit-bash-is-horrendously-slow-in-windows-7) helps. – Piotr Praszmo Jun 14 '12 at 11:37
  • @PaulR but I don't think it is as slow to result in a 3min lag. I think there were other processes running in windows when the OP tried this. Or he used something which is significantly different in windows and Linux inside his program. – Pavan Manjunath Jun 14 '12 at 11:39
  • 5
    It's not just the spawning of processes, but the emulation of `fork` which makes Cygwin so slow. `fork` is something that is not natively supported under the Win32 API, so it has to do a lot of hackery and copying to get the same effect as under POSIX (normally this is done by copying the page table and making the pages copy-on-write, and that's it). – Damon Jun 14 '12 at 11:39
  • 7
    can you show us the code?, what language are you using? is it a bash script? does it have a big loop? without more information it's hard to help you, @PaulR is right tho, AFAIK fork is slow and even frequently fails under some conditions – KurzedMetal Jun 14 '12 at 11:41
  • The bash script called some binary files compiled by g++ on linux platform. So it failed on cygwin. Thank you for help. – vv1133 Jun 15 '12 at 14:23
  • 3
    possible duplicate of [How to speed up Cygwin?](http://stackoverflow.com/questions/2512892/how-to-speed-up-cygwin) – Warren Young Jun 15 '12 at 16:54

1 Answers1

3

As others have already mentioned, Cygwin's implementation of fork and process spawning on Windows in general are slow.

Using this fork() benchmark, I get following results:

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.

Using time (for i in {1..10000};do cat /dev/null;done) to benchmark process spawning performance, I get following results:

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

Hardware specifications:

  • cygwin: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
  • arch: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  • debian: Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz

So as you see, no matter what you use, Cygwin will always operate worse. It loses hands down even to worse hardware (cygwin vs. debian in this benchmark, as per this comparison).

rr-
  • 14,303
  • 6
  • 45
  • 67