ResourceString VS Const for string literals

I have several thousand string literals in a Delphi application. They were isolated in a separate file and used for localization in the past.

Now I no longer need localization.

Is there a performance limitation when using resourcestring compared to equal constants.

Can I change them to CONST?

+7
source share
3 answers

The string const calls the _UStrLAsg call, and the resource string ends with LoadResString .

Since the question of speed has nothing to do with the test.

 resourcestring str2 = 'str2'; const str1 = 'str1'; function ConstStr1: string; begin result := str1; end; function ReceStr1: string; begin result := str2; end; function ConstStr2: string; begin result := str1; end; function ReceStr2: string; begin result := str2; end; procedure Test; var s1, s2, s3, s4: string; begin s1 := ConstStr1; s2 := ReceStr1; s3 := ConstStr2; s4 := ReceStr2; end; 

The first time I used AQTime, added to DelphiXE, to profile this code, and here is the result. The time column shows machine cycles.

Report from AQTime

I may have made a lot of newbie mistakes profiling this, but as I see it, there is a difference between const and resourcestring . If the difference is noticeable to the user, it depends on what you do with the string. In a loop with many iterations, this can make a difference, but it is used to display information to users, not so much.

+8
source

Since they are stored in a single file, which apparently does little (well done!), There is no reason not to check it. I predict that this will not affect performance, but I think it depends on what else you are doing in your application.

0
source

Resource lines carry overhead.

Compared to displaying such a line or writing it to a file or database, there is not much overhead.

On the other hand, it’s just a switch from the resourcestring to const keyword (and vice versa if you ever think about localization again).

-one
source

All Articles