April 29, 2012

herophuong herophuong
Lab Rat
14 posts

Qt libs linking impact on speed of C++ code

 

Now my group is doing a small project assigned by our teacher. The task is to create a mini search engine in C/C++ which indexes text files and allows querying to search through them.
What we concern now is the impact of Qt libs linking upon the speed of the C++ code part. We have over 2000 text files (about 134MB) to index. With CLI-only version, the program takes nearly 80 seconds while in no-GUI mode of GUI version, the program takes 200 seconds. We are keeping these two version on https://github.com/herophuong/Search-engine [github.com]. “no-GUI mode”‘s code part of the GUI version is pure C++ and is exactly the same as CLI-only version’s code. May some experts here can explain this for us. Thanks in advance.

11 replies

April 29, 2012

koahnig koahnig
Area 51 Engineer
2891 posts

The question is if you are not comparing apples and pears?
Is your C++ compiled in release mode and optimized for speed?
I have noted in some of my applications that debug mode required quite a bit of time to load everything, while the release mode compilation was much faster. However, this was on Windows.

April 29, 2012

herophuong herophuong
Lab Rat
14 posts

Is your C++ compiled in release mode and optimized for speed?

Yes, I compile both version with -O3 flag (which is default for release mode of CMake).

April 29, 2012

ZapB ZapB
Ant Farmer
1424 posts

This is where a profiling tool such as valgrind comes in very useful.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 29, 2012

Wilk Wilk
Lab Rat
120 posts

Hello
Try to use gprof to find out which function takes most time.
Also you may try to minimize using of text output (I mean information about current progress) during processing and avoid using of Qt containers inside your algorithm (as I’ve seen you don’t do it).

April 30, 2012

herophuong herophuong
Lab Rat
14 posts

ZapB wrote:
This is where a profiling tool such as valgrind comes in very useful.

I have only used valgrind to detect memory leak. Thus I thought that this is the only function of valgrind. Thanks for remind me.

Wilk wrote:
Hello
Try to use gprof to find out which function takes most time.

Thanks for suggesting the tool. I will give it a try.

April 30, 2012

ZapB ZapB
Ant Farmer
1424 posts

Take a look at the cachegrind tool of valgrind and also kcachegrind to visualise the results.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 30, 2012

herophuong herophuong
Lab Rat
14 posts

Really thanks for all of you, guys. After using valgrind to analyze the run, I’ve resolved almost all bottlenecks on the program. The speeds of CLI-only version and no-GUI mode of GUI version are the same now and both of them have been reduced to 50s. LOL.

April 30, 2012

ZapB ZapB
Ant Farmer
1424 posts

Great news! Congratulations.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 30, 2012

herophuong herophuong
Lab Rat
14 posts

Though my question is still there because what I’ve done is only optimize CLI-only version and then merge the code with the GUI version (which means only the C++ code part is affected). Why are those speeds are not the same in the first place? May be I don’t really need the answer for now but in the future projects, the problem may raise up in different situation.

April 30, 2012

ZapB ZapB
Ant Farmer
1424 posts

Does your GUI do any additional work such as displaying progress info? I’ve not had a chance to look at your actual code.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 30, 2012

herophuong herophuong
Lab Rat
14 posts

You can see the code of main.cpp in gui branch. (The link is at the first post). If the —no-gui option is passed, the code path is redirected to not run the GUI loop and the program will run as the CLI version do. What I’ve asked is about the no-GUI mode of GUI version, not its GUI mode.
The GUI mode actually runs slower because of GUI stuff but I think I can not do anything about that. GUI needs to display progress so we don’t feel it is frozen while it’s indexing files.

 
  ‹‹ How to avoid type comparision using polymorphism      Global "get" functions through with Singleton, is it a good idea? ››

You must log in to post a reply. Not a member yet? Register here!