fork download
  1. #ifndef QFILEVSIFSTREAM_H
  2. #define QFILEVSIFSTREAM_H
  3.  
  4. #include <QWidget>
  5. #include <QFile>
  6. #include <QtDebug>
  7. #include <fstream>
  8. #include <ctime>
  9.  
  10. using namespace std;
  11.  
  12. namespace Ui {
  13. class QFileVSifstream;
  14. }
  15.  
  16.  
  17.  
  18. class QFileStopWatch
  19. {
  20. public:
  21. QFileStopWatch() : start(std::clock()){}
  22. ~QFileStopWatch();
  23. private:
  24. std::clock_t start;
  25. };
  26.  
  27. class ifstreamStopWatch
  28. {
  29. public:
  30. ifstreamStopWatch() : start(std::clock()){}
  31. ~ifstreamStopWatch();
  32. private:
  33. std::clock_t start;
  34. };
  35.  
  36.  
  37.  
  38.  
  39. class QFileVSifstream : public QWidget
  40. {
  41. Q_OBJECT
  42.  
  43. public:
  44. explicit QFileVSifstream(QWidget *parent = 0);
  45. ~QFileVSifstream();
  46.  
  47. private slots:
  48. void on_qfileButton_clicked();
  49. void on_ifstreamButton_clicked();
  50.  
  51. private:
  52. Ui::QFileVSifstream *ui;
  53. };
  54.  
  55. #endif // QFILEVSIFSTREAM_H
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. #include "qfilevsifstream.h"
  71. #include "ui_qfilevsifstream.h"
  72.  
  73. QFileVSifstream::QFileVSifstream(QWidget *parent) : QWidget(parent), ui(new Ui::QFileVSifstream)
  74. {
  75. ui->setupUi(this);
  76. }
  77.  
  78. QFileVSifstream::~QFileVSifstream()
  79. {
  80. delete ui;
  81. }
  82.  
  83.  
  84.  
  85. QFileStopWatch::~QFileStopWatch()
  86. {
  87. QString filecontents;
  88. QString line = "";
  89. QFile file("in.txt");
  90. file.open(QIODevice::ReadOnly | QIODevice::Text);
  91.  
  92. while (!file.atEnd()) {
  93. line = file.readLine().constData();
  94. filecontents.append(line);
  95. }
  96.  
  97. clock_t total = clock()-start;
  98. qDebug() << "Total ticks: " << total << "/ Total seconds: " << double(total)/CLOCKS_PER_SEC;
  99.  
  100. file.close();
  101. }
  102.  
  103.  
  104.  
  105. ifstreamStopWatch::~ifstreamStopWatch()
  106. {
  107. string filecontents;
  108. string line = "";
  109. ifstream file;
  110.  
  111. file.open("in.txt");
  112.  
  113. while (!file.eof())
  114. {
  115. getline(file, line);
  116. filecontents.append(line);
  117. }
  118.  
  119. clock_t total = clock()-start;
  120. qDebug() << "Total ticks: " << total << "/ Total seconds: " << double(total)/CLOCKS_PER_SEC;
  121.  
  122. file.close();
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. void QFileVSifstream::on_qfileButton_clicked()
  131. {
  132. qDebug() << "Started QFileStopWatch test.";
  133. QFileStopWatch test_qfile;
  134. }
  135.  
  136.  
  137.  
  138. void QFileVSifstream::on_ifstreamButton_clicked()
  139. {
  140. qDebug() << "Started ifstreamStopWatch test.";
  141. ifstreamStopWatch test_ifstream;
  142. }
  143.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty