STL performance test

zhaozj2021-02-08  407

Author homepage

http://www.chenshuo.com

Upload test text and source code

What is the performance of C Standard Template Library - STL, how much is the difference between STLs of different versions? For this, let's make a simple test.

The basic idea of ​​the test is to implement a program with C and C , implement the same functionality, and require the primary data structure of the C program to be implemented with Containers, Algorithms, etc. in STL. Then compare the performance of the two programs, see who is fast, how much is fast.

Because the water C / C level is extremely limited, the Code written cannot be taken, in order to ensure fairness, it is best to use a Code written by a recognized master character to do this test. In the third chapter of "The Practice Of Programming" (Chinese translation ", the author Brian W. Kenighan wrote CODE with C and C , and his old man's program is used here. The most suitable. This app is used to implement the "Markov chain algorithm", please see the Appendix 1 of this article for details on the Markov chain algorithm.

I downloaded the corresponding code in "The Practice Of Programming" book http://tpop.awl.com to record the time of the program, I added a few statements in the code (Take "/ * added by Chen Shuo * / "indicates that the complete code is located in Appendix 2 of this article.

Test machine:

Machine 1: PII 300 with 512K L2 Cache, Intel 440LX motherboard 66MHz Overseas, 64M RAM, Installation P - WIN98 SE; Machine 2: PII 350 with 512K L2 Cache, Intel 440BX Motherboard 100MHz Overseofa, 128M RAM, Install Windows2000 Professional Edition with service pack 2.

Compile environment: (both compiled under Windows)

1, Microsoft Visual C 6.0 with Service Pack 5

2, CYGWIN: DLL VER 1.3.2 and GNU C 2.95.3 (downloaded from http://www.cygwin.com)

3, Borland C Compiler 5.5.1 for Free (Download from http://www.borland.com)

There are three documents to be compiled, named Markov.c; using List's Markov_L.cpp; use Deque's Markov_d.cpp. Among them, Markov.c needs to compile links with EPRINTF.C.

Compile command line parameters (all open speed optimization options, compiled executable executive in DOS PROMPT):

I installed the BCC in C: / BCC, Cygwin installed in C: / Cygwin. So the setting of environmental variables is:

SET MSDEVDIR = C: / Progra ~ 1 / Micros ~ 3 / Common / MSDEV98

SET MSVCDIR = C: / Progra ~ 1 / Micros ~ 3 / VC98

SET PATH = "C: / Progra ~ 1 / Micros ~ 3 / VC98 / BIN"; C: / Windows; C: / Windows / Command; C: / BCC / BIN;

SET PATH =% path%; C: / cygwin / bin "C: / progra ~ 1 / micros ~ 3 / Common / MSDEV98 / BIN";

Set include = c: / progra ~ 1 / micros ~ 3 / vc98 / incrude;

Set lib = c: / progra ~ 1 / micros ~ 3 / vc98 / lib;

1. Take the compilation of Markov_l.cpp as an example. To distinguish the EXE file generated by different compilers, you need to specify the name of the generated EXE file, the blue part is the name of the file.

G -o g_l.exe -o4 markov_l.cpp

BCC32 -IC: / bcc / include -lc: / bcc / lib -o2 -6 -eb_l.exe markov_l.cpp

CL / G6 / O2 / OG / GX / MT /FEV_L.EXE MARKOV_L.CPP

2, then compile MARKOV.C as an example

G -o g_c.exe -o4 markov_l.c EPRINTF.C

BCC32 -IC: / bcc / include -lc: / bcc / lib -O2 -6 -EB_C.EXE MARKOV_L.C EPRINTF.C

CL / G6 / O2 / OG / MT / GX /FEV_C.EXE MARKOV.C EPRINTF.C

In this way we compile 3 programs in three compilers, get 9 EXE files, namely:

Markov.c

Markov_l.cpp

Markov_d.cpp

GNU C 2.95.3

g_c.exe

g_l.exe

g_d.exe

BCC 5.5.1

B_c.exe

B_L.exe

B_d.exe

VC6

v_c.exe

v_l.exe

v_d.exe

In order to verify the correctness of each program, I made a simple test with License.txt (15095bytes, 2239 words) with BCC 5.5 (such as C: / BCC> B_D

Test method: Typing in the command line

g_c g1.txt

After execution, open G1.txt, the last line "The Time Was:" is the time executed, while see if there is 10,000 words, if less than 10,000, you need to perform the test again, so that the fair test is guaranteed.

For convenience, I wrote a small program to automatically test: an EXE file executes 30 times, generates 30 TXT files. The top three do not count, the number of banks in 27 files reached 10000, and their average execution time is obtained.

The test results made on the two machines are as follows, and the unit is seconds:

PII 300 with 64M RAM PII 350 with 128M RAM B_C 0.432

0.330

B_D> 300 *

5.567

B_L> 300 *

5.607

g_c 0.463

0.336

g_d 3.366

2.581

G_l 2.142

1.707

V_C 0.568

0.459

v_d> 300 *

131.6 *

V_L 2.714

2.080

Note: Anyone marked with * people, the hard disk is rampted when the program is executed, and the estimated disk I / O takes a lot of time.

Preliminary analysis The above data can be obtained:

1, Borland C 5.5.1 STL's performance is relatively low, and it seems to be more in-memory, and when executed on a larger machine, the disk exchange will take a lot of time. 2, Visual C 6.0 STL, List is still, but at least Deque has problems, consumes memory, and the result disks exchanged a lot of time, but unfortunately I don't have 256M memory machines. Test.

3, GNU C 2.95.3 The STL performance is better, and there is no problem in executing the memory smaller machine.

4. Carefully designed C procedures are faster than implementing the same functionality and C using STL. In this test, the function of the C program is mainly implemented by the STL Container, and the performance of STL has more than 90% of the performance of the entire program, so this big gap is displayed.

Let's take a pick-up flower to pick up the wood, put the STL of the GNU C to the other two compilers to see what effect.

Download SGI STL 3.3 at www.sgi.com, watching FAQ when downloading, you know that SGI STL3.3 is mixed with Visual C 5.0, you need to replace iostream.h; and support SGI There is no Borland C in the STL's compiler.

Release the STL.ZIP to C: / Program Files / Microsoft Visual Studio / VC98 / include / SGISTL. And reset the environment variable:

Set include = c: / progra ~ 1 / micros ~ 3 / vc98 / include / sgistl; c: / progra ~ 1 / micros ~ 3 / vc98 / incrude

Then change the markov_l.cpp with the #include in markov_d.cpp to #include

Compile success with CL / G6 / O2 / OG / GX / MARKOV_D.CPP, so that two EXE files are obtained: v_l_sgi.exe with v_d_sgi.exe, the former is Markov_l.cpp Compilation Generation. Below is the average execution time of these two EXE:

PII 300 with 64M RAM PII 350 with 128M RAM V_L_SGI 1.375

1.074

v_d_sgi 1.943

1.597

Wow! It is better than GNU C itself! Of course, this simple test does not prove that SGI STL and VC6 cooperate with tacit understanding, interested friends can further test.

But things did not go well on Borland C 5.5.1, I tried a lot of ways, but the program could not use SGI STL. Interested friends can go to www.stlport.org to download Stlport 4.5 and use Borland C 5.5.1 to use to see how performance.

According to myan: "Borland uses Rogue Wave STLs the worst; STL in Visual C is a personal work of famous master PJ Plauger, with better performance, but its Queue component is very efficient, caution.", Here you can Supplement is that the demary efficiency of VC6 is also very poor, caution.

Adidue: I am undergraduate from Beijing Normal University. When this article (October 2, 2001), I just went to the big two. This is my C beginner, some experience in the process of learning, write Be a reference to me.

My mailbox: chenshuo@chenshuo.com, Person Homepage: http://www.chenshuo.com, welcome to visit. Author Home http://www.chenshuo.com Upload Test Text and Source Codes

转载请注明原文地址:https://www.9cbs.com/read-422.html

New Post(0)