Mail Archives: djgpp/1999/01/20/02:59:02
From: | dyliu AT ms1 DOT hinet DOT net (Dong-Yueh Liu)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Question about efficiency: vector vs. deque
|
Date: | Wed, 20 Jan 1999 07:53:34 GMT
|
Organization: | New Silkera Network
|
Lines: | 30
|
Message-ID: | <36a5846a.17595250@news.silkera.net>
|
NNTP-Posting-Host: | ts0037.tc.silkera.net
|
Mime-Version: | 1.0
|
X-Newsreader: | Forte Agent 1.5/32.451
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I write a simple program to compare the efficiency of vector and
deque. The code is like the following:
const int loop = 10000;
const int size = 2048;
vector<int> v1(size), v2(size);
deque<int> q1(size), q2(size);
time_t t1 = clock();
for (j = 0; j < loop; j++)
copy(v1.begin(), v1.end(), v2.begin());
time_t t2 = clock();
for (j = 0; j < loop; j++)
copy(q1.begin(), q1.end(), q2.begin());
time_t t2 = clock()
The program is compile with -O3 option to turns on optimizations.
The gcc version is 2.81. The run-time measured of the two loops
in my PC are:
vector: 3.9011 seconds
deque: 3.2967 seconds
I am amazed by the result since I expected that vector should be
faster the deque, but the result is reverse. The following is that
I use VC++ 6.0 to compile the same program:
vector: 0.961 seconds
deque: 4.446 seconds
Can anyone explain why the efficiency of vector is worse than
deque using gcc2.81?
- Raw text -