在VS 2012中调试STL

debugging STL in VS 2012

本文关键字:调试 STL 2012 VS      更新时间:2023-10-16

根据这里和其他地方的帖子,我试图通过设置_NO_DEBUG_HEAP_SECURE_SCL_HAS_ITERATOR_DEBUGGING符号来加速VS 2012调试(本机C++,STL)。

没有运气。

我编写了一个基本的测试程序,用于解析一个大型文本文件(100,000 行,100 列),然后......

释放模式下的输出:

     read 102595 lines in 6.051 seconds

调试模式下的输出:

     read 102595 lines in 317.979 seconds    <==  50x slower, ouch !!!

下面是完整的源代码(C++控制台应用,没有预编译的标头)。#define 语句没有任何效果。调试速度仍然慢得令人难以忍受。 有什么建议吗?

// testAppDebugSTL.cpp : Defines the entry point for the console application.
//
#ifdef _DEBUG
    #define _SECURE_SCL             0
    #define _HAS_ITERATOR_DEBUGGING 0
    #define _NO_DEBUG_HEAP          1
#endif
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
int main(int argc, char** argv[])
{
    std::ifstream                          f ("c:\temp\largeFile.csv");
    std::vector<std::string>               lines;
    std::vector<std::vector<std::string> > tokenized_lines;
    size_t                                 num_lines = 0;
    clock_t tBeg = clock();
    while(!f.eof())
    {
        std::string line;
        std::getline(f, line);
        if (!f.eof())
        {
            lines.push_back(line);   num_lines++;
            std::stringstream        ss(line);
            std::string              token;
            std::vector<std::string> tokens;
            while (std::getline(ss, token, ',')) 
            {
                tokens.push_back(token);
            }
            tokenized_lines.push_back(tokens);
        }   
    }
    clock_t tEnd = clock();
    std::cout << "read " << num_lines << " lines in " <<  double(tEnd - tBeg)/CLOCKS_PER_SEC << " seconds";
    return 0;
}

更改发布模式以输出调试符号。 一开始调试优化的发布版本有点奇怪,但你会习惯的(阅读一些汇编程序的能力会有所帮助)。

还要记住先在小型数据集上运行测试。