Эх сурвалжийг харах

Cutelyst optmization (#6784)

* cutelyst: Optimize Fortunes test

* cutelyst: use mimalloc allocator
Daniel Nicoletti 4 жил өмнө
parent
commit
7147323df3

+ 1 - 0
frameworks/C++/cutelyst/build.sh

@@ -7,6 +7,7 @@ export CUTELYST_VER=3.1.0
 apt update -qq && \
     apt install -yqq --no-install-recommends \
     cmake \
+    git \
     pkg-config \
     qtbase5-dev \
     libqt5sql5-mysql \

+ 11 - 2
frameworks/C++/cutelyst/src/CMakeLists.txt

@@ -1,15 +1,23 @@
-cmake_minimum_required(VERSION 3.6.0 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
 
 project(cutelyst_benchmarks LANGUAGES CXX)
 
 cmake_policy(SET CMP0069 NEW)
 
+include(FetchContent)
+
+FetchContent_Declare(
+  mimalloc
+  GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
+  GIT_TAG        b3b0fb58326a96beea1f4872bc1489d1d9fda7e0 # v2.0.2
+)
+FetchContent_MakeAvailable(mimalloc)
+
 find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core Network Sql)
 find_package(ASqlQt5 0.43.0 REQUIRED)
 find_package(Cutelyst3Qt5 3.1 REQUIRED)
 find_package(Cutelee6Qt5 6.0.0 REQUIRED)
 find_package(PostgreSQL REQUIRED)
-find_package(mimalloc 1.0)
 
 # Auto generate moc files
 set(CMAKE_AUTOMOC ON)
@@ -69,6 +77,7 @@ target_link_libraries(cutelyst-benchmarks
     Qt5::Network
     Qt5::Sql
     ASqlQt5::Core
+    mimalloc
 )
 if (mimalloc_FOUND)
     target_link_libraries(cutelyst-benchmarks PUBLIC mimalloc)

+ 15 - 15
frameworks/C++/cutelyst/src/fortunetest.cpp

@@ -28,10 +28,10 @@ void FortuneTest::fortunes_raw_p(Context *c)
         fortunes.reserve(result.size());
         auto it = result.begin();
         while (it != result.end()) {
-            fortunes.push_back({it[0].toInt(), it[1].toString()});
+            fortunes.emplace_back(Fortune{it[0].toInt(), it[1].toString()});
             ++it;
         }
-        fortunes.push_back({0, QStringLiteral("Additional fortune added at request time.")});
+        fortunes.emplace_back(Fortune{0, QStringLiteral("Additional fortune added at request time.")});
 
         std::sort(fortunes.begin(), fortunes.end(), [] (const Fortune &a1, const Fortune &a2) {
             return a1.message < a2.message;
@@ -160,24 +160,24 @@ FortuneList FortuneTest::processQuery(Context *c, QSqlQuery &query)
 
 void FortuneTest::renderRaw(Context *c, const FortuneList &fortunes) const
 {
-    QString out;
-    out.append(QStringLiteral("<!DOCTYPE html>"
-                              "<html>"
-                              "<head><title>Fortunes</title></head>"
-                              "<body>"
-                              "<table>"
-                              "<tr><th>id</th><th>message</th></tr>"));
+    QByteArray out;
+    out.append("<!DOCTYPE html>"
+                "<html>"
+                "<head><title>Fortunes</title></head>"
+                "<body>"
+                "<table>"
+                "<tr><th>id</th><th>message</th></tr>");
     out.reserve(4096);
 
     for (const Fortune &fortune : fortunes) {
-        out.append(QStringLiteral("<tr><td>"))
-                .append(QString::number(fortune.id))
-                .append(QStringLiteral("</td><td>"))
-                .append(fortune.message.toHtmlEscaped())
-                .append(QStringLiteral("</td></tr>"));
+        out.append("<tr><td>")
+            .append(QByteArray::number(fortune.id))
+            .append("</td><td>")
+            .append(fortune.message.toHtmlEscaped().toUtf8())
+            .append("</td></tr>");
     }
 
-    out.append(QStringLiteral("</table></body></html>"));
+    out.append("</table></body></html>");
 
     auto response = c->response();
     response->setBody(out);

+ 1 - 0
frameworks/C++/cutelyst/src/main.cpp

@@ -1,5 +1,6 @@
 
 #include "cutelyst-benchmarks.h"
+#include "mimalloc-new-delete.h"
 
 #include <QCoreApplication>