Post by Thomas(times are MilliSecond)
|fstream |TFileStream |File |TMemoryStream
--------------------------------------------------------------
BCB 2006 time |344-390 | 124-181 |104-188 |233-250
BCB 6 time |0 - 16 | 125-150 |104-125 |234-280
do you have any idea?
I think your example is misleading here is modified example that uses
only STL and windows API:
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <locale>
#include <windows.h>
//---------------------------------------------------------------------------
void dotest() {
int n[10000];
DWORD dwStart, dwEnd, dwTotal = 0;
std::ofstream out;
for (int pos = 0; pos < 10000; pos++) {
n[pos] = 0;
out.open("test",std::ios::binary);
if (!out.is_open()) {
std::cout << "Error" << std::endl;
}
out.imbue(std::locale::classic());
dwStart = ::GetTickCount();
out.write((char*)&n,sizeof(n));
dwEnd = ::GetTickCount();
dwTotal += (dwEnd - dwStart);
out.close();
out.clear();
}
std::cout << dwTotal << " msecs" << std::endl;
}
HANDLE openfile(const char* fname) {
HANDLE fileHandle_ = ::CreateFile( fname,
GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL );
if (fileHandle_ == INVALID_HANDLE_VALUE)
fileHandle_ = NULL;
return fileHandle_;
}
void dotest2() {
int n[10000];
DWORD dwStart, dwEnd, dwTotal = 0;
DeleteFile("test");
HANDLE out=NULL;
DWORD dwrt = 0;
for (int pos = 0; pos < 10000; pos++) {
n[pos] = 0;
out = openfile("test");
if (NULL == out) {
std::cout << "Error" << std::endl;
break;
}
dwStart = ::GetTickCount();
WriteFile(out,&n[0],sizeof(n),&dwrt,NULL);
dwEnd = ::GetTickCount();
CloseHandle(out);
DeleteFile("test");
out = NULL;
dwTotal += (dwEnd - dwStart);
}
std::cout << dwTotal << " msecs" << std::endl;
}
int __cdecl main(int argc, char* argv[]) {
(argc), (argv);
dotest();
dotest2();
return 0;
}
//---------------------------------------------------------------------------
Both executables compiled from command line like this:
bcc32 -tWC -v- -k- -O2 -w Unit1.cpp
Here are my results:
time total (STL) time total(API)
Turbo C++ (BDS 2006) : 37463 msecs 1547 msecs
Borland Free compiler (5.5.1): 1142 msecs 1421 msecs
Accept that BDS has slower STL and RTL. Instead stop using IOStream or
VCL and turn to Windows API which is the faster way.