Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/timbl/TimblExperiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ namespace Timbl {
std::string outStreamName;
std::ifstream testStream;
std::ofstream outStream;
std::vector<char> outStreamBuf; // large write buffer for outStream
unsigned long ibCount;
ConfusionMatrix *confusionInfo;
std::vector<Instance> instances;
Expand Down
16 changes: 15 additions & 1 deletion src/TimblExperiment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,12 @@ namespace Timbl {
if ( Verbosity(MATCH_DEPTH) ){
outfile << " " << matchDepth() << ":" << (matchedAtLeaf()?"L":"N");
}
outfile << endl;
// Use '\n' rather than std::endl: endl flushes the output stream on every
// classified line. Combined with the larger output buffer set in
// initTestFiles(), letting lines accumulate turns ~one write() per line
// into a handful of large writes, which dominates testing time on large
// files. The stream is flushed when it is closed at the end of testing.
outfile << '\n';
showBestNeighbors( outfile );
}

Expand Down Expand Up @@ -1404,6 +1409,15 @@ namespace Timbl {
if ( checkTestFile() ){
outStream.close();
outStream.clear(); // just to be shure. old G++ libraries are in error here
// Give the output stream a large buffer before opening it. The
// default buffer is tiny, so writing one result per test instance
// turns into a great many small write() syscalls that dominate
// testing time on large files; a 1 MB buffer batches them into a
// handful of large writes. (pubsetbuf must precede open() to apply.)
if ( outStreamBuf.empty() ){
outStreamBuf.resize( 1u << 20 );
}
outStream.rdbuf()->pubsetbuf( outStreamBuf.data(), outStreamBuf.size() );
outStream.open( OutFileName, ios::out | ios::trunc );
return true;
}
Expand Down
Loading