#1 2016-05-26 20:17:01

ertank
Member
Registered: 2016-03-16
Posts: 163

Code to execute faster

Hi,

Trying to save as many CPU cycles as possible.

Using OnKeyPress event of a TEdit. Want to Check if Key is 'x' character (case insensitive). CharCase property of the component is ecNormal. Current code is:

if SynCommons.UpperCase(Key) = 'X' then
begin
end;

I have checked UpperCase function and it seems to do lots of things inside. I have changed my code as follows:

if Key = 'x' or Key = 'X' then
begin
end;

However, I do wonder if there is any code that can be proposed to execute faster.

Thanks.

Offline

#2 2016-05-27 08:17:31

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

Re: Code to execute faster

The 2nd version would be faster, indeed.

But I'm sure you are making premature optimization, here.
https://en.wikipedia.org/wiki/Program_o … o_optimize

You should not optimize such code lines, which are not run often.
Use a profiler to show the real bottlenecks of your app, then optimize only what is needed.

Offline

#3 2016-05-27 09:20:17

ertank
Member
Registered: 2016-03-16
Posts: 163

Re: Code to execute faster

I could only find ProDelphi myself.

What other profiler(s) are available free for Delphi 10 which I may try?

Offline

#4 2016-05-27 10:36:08

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

Offline

Board footer

Powered by FluxBB