123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #include "widget.h"
- #include "./ui_widget.h"
- #include <QNetworkReply>
- #include <QNetworkAccessManager>
- #include <QNetworkRequest>
- #include <QTimer>
- #include <QNetworkProxy>
- #include <iostream>
- #include <regex>
- #include <stdlib.h>
- #include "QtFtp.h"
- #include "spdlog/spdlog.h"
- #include "fmtlog.h"
- #include "LightLog.h"
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- m_curlFtp.setFtpIPAndPort("192.168.50.100", 21);
- m_curlFtp.setFtpUsernameAndPassword("microsoft", "19980714Lq");
- SPDLOG_INFO("***** Qt Library *****");
- }
- Widget::~Widget()
- {
- delete ui;
- }
- void Widget::on_pBtn_connect_clicked()
- {
- SPDLOG_INFO("点击了“连接按钮”");
- std::vector<std::string> list;
- m_curlFtp.getFileList("/SSD2/Video", list);
-
- for(const std::string& filename : list)
- {
- QString qfilename = QString::fromLocal8Bit(filename.c_str());
- SPDLOG_INFO("{}", qfilename.toStdString());
- }
- }
- void Widget::on_pBtn_downloadFile_clicked()
- {
- SPDLOG_INFO("点击了“下载文件”");
- std::vector<std::string> fileList;
- bool ret = m_curlFtp.downloadFile("/SSD2/Video/哪吒之魔童降世.mp4", QApplication::applicationDirPath().toStdString() + "/哪吒之魔童降世.mp4");
- if(ret)
- {
- SPDLOG_INFO("下载成功");
- }
- else
- {
- SPDLOG_INFO("下载失败");
- }
- }
- void Widget::on_pBtn_downloadVideo_clicked()
- {
- SPDLOG_INFO("点击了“下载视频”");
- // std::shared_ptr<QtFtp> ftp = std::make_shared<QtFtp>();
- // ftp->setHostAndPort("192.168.50.100");
- // ftp->setUserPasswd("microsoft", "19980714Lq");
- // QString localPath = QApplication::applicationDirPath() + "/v1.mp4";
- // ftp->getFile(localPath, "/SSD1/Video/v1.mp4");
- // ftp->waitFinished(-1);
- // if(ftp->getResult())
- // {
- // SPDLOG_INFO("下载成功");
- // }
- // else
- // {
- // SPDLOG_INFO("下载失败");
- // }
- bool ret = m_curlFtp.createDirectories("SSD1/DOC/123/234");
- if(ret)
- {
- SPDLOG_INFO("文件夹创建成功");
- }else {
- SPDLOG_WARN("文件夹创建失败");
- }
- }
- void Widget::on_pBtn_logSpeed_clicked()
- {
- SPDLOG_INFO("点击了“日志速度”");
- /* 开始时间点1 */
- std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
- for(int i = 0; i < 100000; i++)
- {
- SPDLOG_INFO("{}", "你好,这是日志速度的对比,这个是SPDLOG在打印日志");
- }
- /* 结束时间点1 */
- std::chrono::steady_clock::time_point spdlogEnd = std::chrono::steady_clock::now();
- for(int i = 0; i < 100000; i++)
- {
- FMTLOG_INFO("{}", "你好,这是日志速度的对比,这个是FMTLOG在打印日志");
- }
- std::chrono::steady_clock::time_point fmtlogEnd = std::chrono::steady_clock::now();
- /* 使用std::cout */
- for(int i = 0; i < 100000; i++)
- {
- std::cout << "你好,这是日志速度的对比," << "这个是std::cout在打印日志" << std::endl;
- }
- std::chrono::steady_clock::time_point coutEnd = std::chrono::steady_clock::now();
- /* 使用printf */
- for(int i = 0; i < 100000; i++)
- {
- printf("%s\n","你好,这是日志速度的对比,这个是printf在打印日志");
- }
- std::chrono::steady_clock::time_point printfEnd = std::chrono::steady_clock::now();
- /* 使用QDebug */
- for(int i = 0; i < 100000; i++)
- {
- qDebug() << "你好,这是日志速度的对比," << "这个是QDebug在打印日志";
- }
- std::chrono::steady_clock::time_point qDebugEnd = std::chrono::steady_clock::now();
- /* 使用LightLog */
- for(int i = 0; i < 100000; i++)
- {
- QLOG_INFO("你好,这是日志速度的对比," + "这个是LightLog在打印日志");
- }
- std::chrono::steady_clock::time_point lightLogEnd = std::chrono::steady_clock::now();
- /* 计算时间 */
- std::chrono::duration<double> spdlogTime = std::chrono::duration_cast<std::chrono::duration<double>>(spdlogEnd - start);
- std::chrono::duration<double> fmtlogTime = std::chrono::duration_cast<std::chrono::duration<double>>(fmtlogEnd - spdlogEnd);
- std::chrono::duration<double> coutTime = std::chrono::duration_cast<std::chrono::duration<double>>(coutEnd - fmtlogEnd);
- std::chrono::duration<double> printfTime = std::chrono::duration_cast<std::chrono::duration<double>>(printfEnd - coutEnd);
- std::chrono::duration<double> qDebugTime = std::chrono::duration_cast<std::chrono::duration<double>>(qDebugEnd - printfEnd);
- std::chrono::duration<double> lightLogTime = std::chrono::duration_cast<std::chrono::duration<double>>(lightLogEnd - qDebugEnd);
- /* 打印时间 */
- SPDLOG_INFO("SPDLOG打印耗时: {}", spdlogTime.count());
- SPDLOG_INFO("FMTLOG打印耗时: {}", fmtlogTime.count());
- SPDLOG_INFO("std::cout打印耗时: {}", coutTime.count());
- SPDLOG_INFO("printf打印耗时: {}", printfTime.count());
- SPDLOG_INFO("QDebug打印耗时: {}", qDebugTime.count());
- SPDLOG_INFO("LightLog打印耗时: {}", lightLogTime.count());
- }
|