单独的循环如何影响独立的早期循环的性能?
我的第一个循环读取一些大文本文件并计算行/行.在malloc之后,第二个循环填充分配的矩阵.
如果第二个循环被注释掉,则第一个循环需要1.5秒.但是,使用第二个循环进行编译会减慢第一个循环,现在需要30-40秒!
换句话说:第二个循环以某种方式减慢第一个循环.我试图改变范围,更改编译器,更改编译器标志,更改循环本身,将所有内容放入main(),使用boost :: iostream甚至在共享库中放置一个循环,但在每次尝试中都会出现同样的问题!
第一个循环很快,直到用第二个循环编译程序.
编辑:这是我的问题的完整示例------------>
#include <iostream>
#include <vector>
#include "string.h"
#include "boost/chrono.hpp"
#include "sys/mman.h"
#include "sys/stat.h"
#include "fcntl.h"
#include <algorithm>
unsigned long int countLines(char const *fname) {
static const auto BUFFER_SIZE = 16*1024;
int fd = open(fname, O_RDONLY);
if(fd == -1) {
std::cout << "Open Error" << std::endl;
std::exit(EXIT_FAILURE);
}
posix_fadvise(fd, 0, 0, 1);
char buf[BUFFER_SIZE + 1];
unsigned long int lines = 0;
while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) {
if(bytes_read == (size_t)-1) {
std::cout …Run Code Online (Sandbox Code Playgroud)