Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
This Qt example shows how to use gprof under Qt Creator to profile a simple console application.
Operating system: Ubuntu
IDE: Qt Creator 2.0.0
Project type: Qt4 GUI Application
Compiler: G++ 4.4.1
Libraries used:
- Boost: version 1.40
- Qt: version 4.7.0 (32 bit)
Here follows a step-by-step guide to use gprof to do the profiling of a simple Qt Creator project:
- Go to 'Projects -> Build Settings' and add a custom Build step. Fill in the information as in the screenshot below
- View screenshot
- View your project folder. There will be few files
- View screenshot
- Run the program. The executable 'profile_main' has been created in your project folder
- View screenshot
- Run 'profile_main' and the file 'gmon.out' is created
- View screenshot
- Start a Terminal, go to the project folder and use the command 'gprof profile_main > profile.txt'
- View screenshot
- The file 'profile.txt' will be created
- View screenshot
- The file 'profile.txt' will contain the profiling information
#-------------------------------------------------
#
# Project created by QtCreator 2010-07-24T13:44:59
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = CppGprofExample1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
|
Source code
Profiling results
Here I show the results comparing the five functions, copied from the results file:
Flat profile:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
13.59 1.54 0.28 1 280.00 700.00 void BubbleSort<int>(std::vector<int, std::allocator<int> >&)
12.14 1.79 0.25 1 250.00 670.00 void InsertionSort<int>(std::vector<int, std::allocator<int> >&)
11.65 2.03 0.24 1 240.00 660.00 void SelectionSort<int>(std::vector<int, std::allocator<int> >&)
0.00 2.06 0.00 1 0.00 24.98 void SortVector<int>(std::vector<int, std::allocator<int> >&)
0.00 2.06 0.00 1 0.00 5.02 CreateShuffledVector(unsigned int)
|
Conlusion: as expected, SortVector (a QuickSort) is by far the quickest sorting algorithm.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
