#include <QTime>
#include <QFile>
#include <QByteArray>
#include <QDebug>
#include <iostream>
#include <fstream>
int main()
{
const int size = 200000;
{
std::ofstream out("test.txt");
t.start();
double f = 0.54125432;
int num;
for( int x = 0; x < size; x++ )
{
num = (int)(f*1000000);
out << num << ",";
}
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
}
{
t.start();
double f = 0.54125432;
int num;
for( int x = 0; x < size; x++ )
{
num = (int)(f*1000000);
char buf[7];
::sprintf(buf, "%d", num);
temp1.append( buf );
temp1.append(",");
}
out.write(temp1);
out.flush();
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
}
{
std::ofstream out;
out.open("test.bin", std::ios_base::out | std::ios_base::binary);
t.start();
double f = 0.54125432;
double af[size];
for( int x = 0; x < size; x++ )
{
af[x] =f;
}
out.write((const char*)af, size*sizeof(double));
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
memset(af, 0, size);
std::ifstream in;
in.open("test.bin", std::ios_base::in | std::ios_base::binary);
in.read((char*)af, size*sizeof(double));
in.close();
for( int x = 0; x < 10; x++ )
{
qDebug() << x << ": " << af[x];
}
}
return 0;
}
#include <QTime>
#include <QFile>
#include <QByteArray>
#include <QDebug>
#include <iostream>
#include <fstream>
int main()
{
const int size = 200000;
{
std::ofstream out("test.txt");
QTime t;
t.start();
double f = 0.54125432;
int num;
for( int x = 0; x < size; x++ )
{
num = (int)(f*1000000);
out << num << ",";
}
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
}
{
QFile out("test.txt");
QTime t;
t.start();
double f = 0.54125432;
int num;
QByteArray temp1;
for( int x = 0; x < size; x++ )
{
num = (int)(f*1000000);
char buf[7];
::sprintf(buf, "%d", num);
temp1.append( buf );
temp1.append(",");
}
out.write(temp1);
out.flush();
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
}
{
std::ofstream out;
out.open("test.bin", std::ios_base::out | std::ios_base::binary);
QTime t;
t.start();
double f = 0.54125432;
double af[size];
for( int x = 0; x < size; x++ )
{
af[x] =f;
}
out.write((const char*)af, size*sizeof(double));
out.close();
qDebug("Time elapsed: %d ms", t.elapsed());
memset(af, 0, size);
std::ifstream in;
in.open("test.bin", std::ios_base::in | std::ios_base::binary);
in.read((char*)af, size*sizeof(double));
in.close();
for( int x = 0; x < 10; x++ )
{
qDebug() << x << ": " << af[x];
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks