Clang ++ fstreams 10X is slower than g ++

Q: Is there a way to speed up the flang flang of the STAN ++ library? (And does anyone know why it is much slower than g ++?)

I am trying to process very large (many GB) binary data files and was surprised to see that the performance was so poor. At first I thought this was due to my code. But I see the same slow work in a compressed example.

I even tried to allocate buffers of different sizes through rdbuf () -> pubsetbuf (), but this did not show much effect.

Here is a simple I / O example:

#include <fstream>

int main() {
    std::ifstream is {"bigSourceFile"};
    std::ofstream os {"bigSourceFileCopy"};

    std::string line;
    while (std::getline (is, line) ) {
        os << line;
    }
}

Here is some code to generate a source file of 1.3 GB. Use this to generate the source file for the readWrite program:

#include <fstream>
#include <string>

std::string createTailStr () {
    std::string result {"__"};
    for (auto i (0); i< 58; ++i) {
        result += 'A'+i;
    }

    return result;
}

int main() {

    std::string tail {createTailStr()};

    std::ofstream os {"bigSourceFile"};

    constexpr auto Lines (20000000ul);
    for (auto i (0); i < Lines; ++i) {
        os << i << tail << '\n';
    }
}

( OSX El Capitan Xcode): ( ) aprox. 50 :

clang++ -std = ++ 11 -o readWrite readWrite.cpp

g++ libstd++ 5 .

llvm std++ llvm.org, ( 90 ).

: clang++: 50 ; g++: 5

+4

Source: https://habr.com/ru/post/1649337/


All Articles