Skip to content

Instantly share code, notes, and snippets.

View mpaperno's full-sized avatar

Max Paperno mpaperno

View GitHub Profile
mpaperno /
Last active December 10, 2022 12:47 badge samples for Touch Portal

Given an existing long-ish UTF8 string, add a newline char and turn it into a byte array (eg. for sending over a socket).

I added some UTF16 characters, so the string length is 500 but the resulting byte length is 606.

Inspired by


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1526 (21H2)
Intel Core i7-7820X CPU 3.60GHz (Kaby Lake), 1 CPU, 16 logical and 8 physical cores
#include <QtTest/QtTest>
#include <QStringBuilder>
class bm_stringBuilder : public QObject
bm_stringBuilder() {}

All tests on STM32F4 @168MHz, with Kingston class 6 8GB SD. All times in micro seconds [us]. The "memory" statistic (where present) is delta of samples taken with luaGetMemUsed() before and after iteration/test (with no GC done in between).

The Lua environment was reloaded between each iteration (except for the tLdScr.lua test which is all one run).

NOTE: The times listed here are really only relevant in comparison to other tests run on the same system. They will vary greatly based on system load, SD card speed/integrity, and other factors. The percentage of change is the most relevant statistic here. The benchmarks were run under "ideal" conditions, using a high-priority thread, to ensure consistent results.