benchlargesync.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This software is in the public domain, furnished "as is", without technical
  3. * support, and with no warranty, express or implied, as to its usefulness for
  4. * any purpose.
  5. *
  6. */
  7. #include "syncenginetestutils.h"
  8. #include <syncengine.h>
  9. using namespace OCC;
  10. int numDirs = 0;
  11. int numFiles = 0;
  12. template<int filesPerDir, int dirPerDir, int maxDepth>
  13. void addBunchOfFiles(int depth, const QString &path, FileModifier &fi) {
  14. for (int fileNum = 1; fileNum <= filesPerDir; ++fileNum) {
  15. QString name = QStringLiteral("file") + QString::number(fileNum);
  16. fi.insert(path.isEmpty() ? name : path + "/" + name);
  17. numFiles++;
  18. }
  19. if (depth >= maxDepth)
  20. return;
  21. for (int dirNum = 1; dirNum <= dirPerDir; ++dirNum) {
  22. QString name = QStringLiteral("dir") + QString::number(dirNum);
  23. QString subPath = path.isEmpty() ? name : path + "/" + name;
  24. fi.mkdir(subPath);
  25. numDirs++;
  26. addBunchOfFiles<filesPerDir, dirPerDir, maxDepth>(depth + 1, subPath, fi);
  27. }
  28. }
  29. int main(int argc, char *argv[])
  30. {
  31. QCoreApplication app(argc, argv);
  32. FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
  33. addBunchOfFiles<10, 8, 4>(0, "", fakeFolder.localModifier());
  34. qDebug() << "NUMFILES" << numFiles;
  35. qDebug() << "NUMDIRS" << numDirs;
  36. QElapsedTimer timer;
  37. timer.start();
  38. bool result1 = fakeFolder.syncOnce();
  39. qDebug() << "FIRST SYNC: " << result1 << timer.restart();
  40. bool result2 = fakeFolder.syncOnce();
  41. qDebug() << "SECOND SYNC: " << result2 << timer.restart();
  42. return (result1 && result2) ? 0 : -1;
  43. }