#1 2023-03-05 10:24:13

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Interesting string conversion benchmark results

Using a simple example as in https://gist.github.com/dkounal/b14ce68 … ffbcb60a53

In win11 with Delphi 11.2 (win32target) I got the following results in ms:
Using string with Greek Characters
string conversion: 2141
rawutf8 conversion: 3307
mormot utf8tostring conversion: 5256
mormot stringtoutf8 conversion: 3834
RTL Utf8ToString conversion: 2083
UTF8Encode conversion: 2514
Finished with Greek Characters

Using string with Latin Characters
string conversion: 1259
rawutf8 conversion: 1555
mormot utf8tostring conversion: 1154
mormot stringtoutf8 conversion: 1715
RTL Utf8ToString conversion: 1097
UTF8Encode conversion: 1134
Finished with Latin Characters

Any comments welcome, just for learning purposes. I am not an expert

Last edited by dcoun (2023-03-05 10:59:10)

Offline

#2 2023-03-05 10:51:09

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Interesting string conversion benchmark results

In win11 compiled with FPC 3.2.3 x86_64-win64-win32/win64 and win64 target and string is declared as 'string'

The results are completely different:
Using string with Greek Characters
string conversion: 2206
rawutf8 conversion: 2065
mormot utf8tostring conversion: 151
mormot stringtoutf8 conversion: 2097
RTL Utf8ToString conversion: 14705
UTF8Encode conversion: 8931
Finished with Greek Characters

Using string with Latin Characters
string conversion: 1996
rawutf8 conversion: 1947
mormot utf8tostring conversion: 152
mormot stringtoutf8 conversion: 2059
RTL Utf8ToString conversion: 5926
UTF8Encode conversion: 6457
Finished with Latin Characters

Last edited by dcoun (2023-03-05 10:55:43)

Offline

#3 2023-03-05 10:52:10

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Interesting string conversion benchmark results

win11 and Delphi 11.2 with win64 target

Using string with Greek Characters
string conversion: 2561
rawutf8 conversion: 3441
mormot utf8tostring conversion: 5563
mormot stringtoutf8 conversion: 4299
RTL Utf8ToString conversion: 2835
UTF8Encode conversion: 3528
Finished with Greek Characters

Using string with Latin Characters
string conversion: 1680
rawutf8 conversion: 1926
mormot utf8tostring conversion: 1514
mormot stringtoutf8 conversion: 2179
RTL Utf8ToString conversion: 1735
UTF8Encode conversion: 1608
Finished with Latin Characters

Offline

#4 2023-03-05 10:56:28

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Interesting string conversion benchmark results

In win11 compiled with FPC 3.2.3 x86_64-win64-win32/win64 and win64 target and string is declared as 'unicodestring'

Using string with Greek Characters
string conversion: 7811
rawutf8 conversion: 6274
mormot utf8tostring conversion: 9197
mormot stringtoutf8 conversion: 7457
RTL Utf8ToString conversion: 10735
UTF8Encode conversion: 5055
Finished with Greek Characters

Using string with Latin Characters
string conversion: 3705
rawutf8 conversion: 3279
mormot utf8tostring conversion: 3910
mormot stringtoutf8 conversion: 3735
RTL Utf8ToString conversion: 3853
UTF8Encode conversion: 3810
Finished with Latin Characters

Last edited by dcoun (2023-03-05 11:01:44)

Offline

#5 2023-03-05 11:06:48

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Interesting string conversion benchmark results

Generally from what I can understand, Delphi's Utf8ToString/UTF8Encode are faster than mormot2's utf8tostring/stringtoutf8 for non latin characters but in FPC it is better to use mormot2's functions
I used the stopwatch for FPC from https://stackoverflow.com/questions/139 … tstopwatch as a fast alternative with the same code

Last edited by dcoun (2023-03-05 11:15:21)

Offline

#6 2023-03-05 21:48:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Interesting string conversion benchmark results

You are comparing apples and oranges, because string is not the same on FPC and Delphi.
As you wrote about string = string and string = UnicodeString. And when you make string = UnicodeString in FPC, I suspect there are some hidden conversion behind the scene.
Really confusing.

In fact, conversion to/from string was never very optimized - but it should not in real programs, where you just need it when you reach the VCL/LCL layer.
So they are not bottleneck in the respect on the UI layer - which will be slower than the text conversion for sure.
In practice, I don't trust micro-benchmarks on identical data in a loop, everything in L1 CPU cache.

Offline

Board footer

Powered by FluxBB