简体   繁体   中英

C Code slower on Windows than on Linux

i'm working on a project that will have builds for Windows and Linux, 32 and 64 bits. This project is based on loading strings for a text file, process it and write results to a SQLite3 database.

On linux it reaches almost 400k sequences per second, compiled by GCC without any optimization. However on Windows it stucks in 100k sequences per second, compiled on VS2010 without any optimization.

I tried using optimizations in compilers but nothing changed.

Is this right? C code on Windows runs slower?

EDIT:

I think i need to be more clear on some points. I made tests with code optimization enabled AND disabled. Performance didn't changed, probably because my program's bottleneck is the time wasted reading data from HD.

This program takes benefits of parallel computing. There a queue where a thread queues processed data and another dequeue to write in the SQLite database. This way i don't think there is any performance lose from this.

Is this right? C code on Windows runs slower?

No. C doesn't have speed. It's the implementations of C that introduce speed. There are implementations that produce fast behaviour (generally "compilers that produce fast machine code") and implementations that produce slow behaviour for both Windows and Linux.

It isn't just Windows and Linux that are significant here, either. Some compilers optimise for specific processors, and will produce slow machine code for any other processors.

I tried using optimizations in compilers but nothing changed.

Testing speed without optimisations enabled makes no sense. However, this does tend to indicate that something else is slow. Perhaps the implementation that produced the library files for SQLite3 client in Windows is an implementation that produces slow code . I'd start by rebuilding the lot (including the SQLite3 library) with full optimisations enabled . Following that, you could try using a profiler to determine where the difference is and use the results to perform intelligent optimisations to your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM