From: Rayne on
Hi all,

I have written a program in Linux and compiled it on GCC. The program
took about one second to run. Then I converted the same program into
something that can run on Windows (Vista) and compiled it using Visual
Studio .NET 2003. However, this program now takes about 9 - 10 seconds
to run (in both debug and release mode).

The program does the following:
It uses the pcap library (WinPcap WpdPack 4.0.2 for Windows) to first
set up a filter using IP addresses. Then going through a folder, it
reads every pcap file in it and runs pcap_loop on each pcap file. The
callback function for pcap_loop checks for certain criteria and writes
the contents to files.

The changes I've made to convert the program from Linux to Windows is:
1) Using FindFirstFile and FindNextFile instead of struct dirent
2) I had to define structures for IP, TCP and UDP myself for the
Windows program, since I can't find netinet/ip.h, netinet/tcp.h and
netinet/udp.h on Windows
3) Using CreateFile and WriteFile instead of fwrite (fwrite was giving
me problems with the output)

Other than that, the program is pretty much kept the same.

I thought the file I/O could be the cause of the difference in speed,
but after commenting out every WriteFile, the Windows program is still
slower. Could using WinPcap in Windows be the cause?

Thank you.

Regards,
Rayne
From: David Schwartz on
On Dec 29, 5:52 pm, Rayne <lancer6...(a)yahoo.com> wrote:

> I thought the file I/O could be the cause of the difference in speed,
> but after commenting out every WriteFile, the Windows program is still
> slower. Could using WinPcap in Windows be the cause?

There are a few ways to track this kind of thing down, but my favorite
way to do it is to note the time on program startup and have a
function that writes an entry to a log file along with the time since
program startup and the time since the last log entry. Then add lines
of code to the program to log when key events happened (when you open
a file, when you finish processing something, and so on).

From those logs, you should be able to tell what each program was
doing for the time it was running. Once you know what the Windows
program is doing for those 8 seconds, the answer should be pretty
clear.

It will likely be something silly, like the Windows program doing lots
of DNS or something.

DS
From: Richard Russell on
On Dec 30, 1:52 am, Rayne <lancer6...(a)yahoo.com> wrote:
> I have written a program in Linux and compiled it on GCC. The program
> took about one second to run. Then I converted the same program into
> something that can run on Windows (Vista) and compiled it using Visual
> Studio .NET 2003. However, this program now takes about 9 - 10 seconds
> to run (in both debug and release mode).

GCC runs fine on Windows (e.g. using mingw or cygwin) so if you're
happy with the performance from GCC, why recompile using Visual
Studio?

http://www.mingw.org/
http://www.cygwin.com/

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

From: Auric__ on
On Wed, 30 Dec 2009 01:52:11 GMT, Rayne wrote:

> I have written a program in Linux and compiled it on GCC. The program
> took about one second to run. Then I converted the same program into
> something that can run on Windows (Vista) and compiled it using Visual
> Studio .NET 2003. However, this program now takes about 9 - 10 seconds
> to run (in both debug and release mode).

[snip]

> I thought the file I/O could be the cause of the difference in speed,
> but after commenting out every WriteFile, the Windows program is still
> slower. Could using WinPcap in Windows be the cause?

It might be because GCC compiles to machine code, while VS.Net compiles to
bytecode that must then be interpreted.

--
Tinsel is really snakes' mirrors.
-- Steven Wright
From: Rayne on
Thanks for the suggestions!

David - I will try that later.

Richard - I was under the impression that cygwin is similar to VMware,
in that Linux and Windows occupy 2 separate memory space, and
communication between programs would be quite inconvenient. Would a
native Windows program be able to easily access the files written (to
a folder) by the Linux program?

Auric - The other portions of the entire program run at the same
speed, this is the only part that runs slower in Windows.