Benchmarking on C++ and Qt4

July 22, 2009

I came up with a idea of cross checking my knowledge about Vectors and Lists. So, I started off with Qt’s QList and QVector. I created a QList and QVector of 50000 object of another class and then iterated each with ‘for’ loop and ‘foreach’ loop separately. Initially my intentions were to study the time being taken by both kind of loops but I ended up studying Lists and Vectors.

What I found out was ‘foreach’ loop takes more time than plain ‘for’ loop but for this also the time taken for traversing QList is far lesser than for QVector. I though that this might be because of some internal problem with Qt4.2 or with my system’s configuration. Thus, I re-wrote the code using STL List and Vector. I was surprised to see same result as I got for the QList and QVector.

Thus, I fially though of trying out my code in some other system but I got the same result. Still, I can’t understand the reason for this behavior.

You can get my code below :

example.h

#include <QtGui>
#include <QtCore>

#define MAX 900000

class Test
{
public:
QString name;
quint32 eid;
QString address;
Test(QString name, quint32 eid, QString address);
Test();
};

class Example
{
public:
Example();
};

class Example2
{
public:
Example2();
};

example.cpp

#include “example.h”

Example::Example()
{
QList<Test> list;
QVector<Test> vector(50000);
qDebug()<<“starting Example”;

QTime currTime = QTime::currentTime();
for(quint32 i = 0; i < 50000; ++i)
{
Test test(QString(“asasasasas”), i, QString(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”));
list.append(test);
}
qDebug()<<“time taken for appending in list= “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
for(quint32 i = 0; i < 50000; ++i)
{
Test test(QString(“asasasasas”), i, QString(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”));
vector.append(test);
}
qDebug()<<“time taken for appending in vector = “<< currTime.msecsTo(QTime::currentTime());
Test temp;
currTime = QTime::currentTime();
foreach(temp, list)
{
Test temp2 = temp;
}
qDebug()<<“foreach list = “<< currTime.msecsTo(QTime::currentTime());

QList<Test>::iterator it;
currTime = QTime::currentTime();
for(it = list.begin(); it != list.end(); ++it)
{
Test temp2 = *it;
}
qDebug()<<“for list = “<< currTime.msecsTo(QTime::currentTime());

quint32 size = list.size();
currTime = QTime::currentTime();
for(quint32 i = 0; i < size; ++i)
{
//Test temp2 = list.at(i);
Test temp2 = list[i];
}
qDebug()<<“for \”i\” list = “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
foreach(temp, vector)
{
Test temp2 = temp;
}
qDebug()<<“foreach vector = “<< currTime.msecsTo(QTime::currentTime());

QVector<Test>::iterator iter;
currTime = QTime::currentTime();
for(iter = vector.begin(); iter != vector.end(); ++iter)
{
Test temp2 = *iter;
}
qDebug()<<“for vector = “<< currTime.msecsTo(QTime::currentTime());

size = vector.size();
currTime = QTime::currentTime();
for(quint32 i = 0; i < size; ++i)
{
//Test temp2 = vector.at(i);
Test temp2 = vector[i];
}
qDebug()<<“for \”i\” vector = “<< currTime.msecsTo(QTime::currentTime());

}

example2.cpp

#include “example.h”
#include <vector.h>
#include <list.h>

Test::Test(QString name, quint32 eid, QString address)
{
this->name = name;
this->eid = eid;
this->address = address;
}

Test::Test()
{
}

Example2::Example2()
{
list<Test> testList;
vector<Test> testVector;
Test testArray[MAX];

QTime currTime = QTime::currentTime();
for(int i = 0; i < MAX; ++i)
{
Test temp(QString(“asasasasas”), i, QString(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”));
testList.push_back(temp);
}
qDebug()<<“time taken for appending in list= “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
for(quint32 i = 0; i < MAX; ++i)
{
Test test(QString(“asasasasas”), i, QString(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”));
testVector.push_back(test);
}
qDebug()<<“time taken for appending in vector = “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
for(quint32 i = 0; i < MAX; ++i)
{
Test test(QString(“asasasasas”), i, QString(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”));
testArray[i] = test;
}
qDebug()<<“time taken for appending in Array = “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
list<Test>::iterator itList;
for(itList = testList.begin(); itList != testList.end(); ++itList)
{
Test temp2 = *itList;
}
qDebug()<<“for loop List = “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
vector<Test>::iterator itVector;
for(itVector = testVector.begin(); itVector != testVector.end(); ++itVector)
{
Test temp2 = *itVector;
}
qDebug()<<“for loop Vector = “<< currTime.msecsTo(QTime::currentTime());

currTime = QTime::currentTime();
for(int i = 0 ; i < MAX; ++i)
{
Test temp2 = testArray[i];
}
qDebug()<<“for loop Array = “<< currTime.msecsTo(QTime::currentTime());
}

main.cpp

#include <QApplication>
#include <example.h>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Example ex1;

Example2 ex2;

return app.exec();
}

var infolink_pid = 46981;


MS Office Live

July 15, 2009

Though I am not a fan of Microsoft, but I really like its MS Office suit. Its awesome, though I do not use it just for the reason that it is Microsoft’s.

At times I do use MS Windows in my laptop, specially when I am in a mood to play some games, but most of the time I prefer using Ubuntu or Fedora.

Yesterday, I came across the news that MS has made it Office suit online. I though of trying it out once. If not use it, at least compare it with Google Docs, which I use at times.

After I took the pain to create an account this is what I get :

MS Does not want Linux user to use its Online Office Suit

MS Does not want Linux user to use its Online Office Suit

Why should an browser application be dependent on some OS?

Now that I have experienced this, I would be reluctant to try out again. Thus, MS ends up loosing customers. I think this was a great thing that MS had come out with but these things ruins all the fun.

var infolink_pid = 46981;


YourStory Entrepreneur Forum – Summer 2009

May 29, 2009

I had been to this forum today and trust me it was just awesome. This is something I was looking forward to and it was totally worth attending this forum. I hope yourstory.in organizes more of this kind of forums.
I was a good place for networking and the talks were really great.
All the talk focused on a basic point for entrepreneur – Passion.
Thanks to Shradha and her team for the forum.


Nano from Sringur is Mamta Banerjee Comes in power?

April 3, 2009

Mamta Banerjee recently participated in a phone in program on a bengali news channel. There she said that she would never ride Tata’s Nano as it has been made from poor people’s blood.
Her answer to a particular question was quite string for me. The question was if there is any chance of Nano being rolled out form Singur if she comes in power. Her reply to the question – “I will first go through the contract they have signed with the West Bengal government and then decide.”
Well whats striking in this was, she had been protesting against the Tata’s Nano project since 2006 which ultimately led to Tata pulling out of West Bengal and shifting the plant to Gujarat. Its almost two and a half years and now she says that she shall read the contract.
Wasn’t she suppose to know what is the contract before she started the protests? It was her protests that led Tata to incur huge losses and she now says that she shall read the contract.
May be my views are wrong in this but I shall like to know where am I wrong.


Disturbing Photo in Newspapers

March 13, 2009

Just like any other day, my day starts with spending some time over the news paper, usually Times Of India.
There was a small snippet in the front page about a boy, 3 years old, who suffers an injury during holi celebration. The snippet said that – “the rod has been removed successfully from the boys body. More info at page 9.” On opening page nine, there was this very disturbing photo of the biy laying in the hospital bed with the rod right through his body.
I just thought, should the newpapers actually provide such disturbing photos?


Evolution of Mac….

January 24, 2009

I was just browsing the regular website and i cam across this.
Check out this link to see how Mac evolved in the last 25 years…
http://content.zdnet.com/2346-9595_22-263589-1.html


Windows 7 better than Vista???

January 9, 2009

I just happened to come accross this comics strip. Quite funny but may be true :D.

Windows 7 better than Vista

Windows 7 better than Vista