Jump to content
Mike Torrettinni

Performance of MOVE vs + for concatenating mixed type values

Recommended Posts

With new 'knowledge', I tested what happens if I add values in consecutive expressions, like this:

 

function PrepareLineForExport2(const aDataIn: TData): string;
begin
  Result := aDataIn.ID1.ToString            + cSeparator;
  Result := Result +  aDataIn.S1            + cSeparator;
  Result := Result +  BoolToStr(aDataIn.B1) + cSeparator;
  Result := Result +  aDataIn.S2            + cSeparator;
  Result := Result +  aDataIn.C1            + cSeparator;
  Result := Result +  aDataIn.S3;
end;

OK, this is now slower:

PrepareLineForExport: 1358 ms (single expression using + )

PrepareLineForExport2: 2242 ms

 

I realize this is probably the most basic thing for most of you, for me this is something really new.

 

Share this post


Link to post
3 minutes ago, Mike Torrettinni said:

With new 'knowledge'

You mean after somebody read the RTL code for you?

  • Haha 2

Share this post


Link to post
15 minutes ago, Mike Torrettinni said:

With new 'knowledge', I tested what happens if I add values in consecutive expressions, like this:

 


function PrepareLineForExport2(const aDataIn: TData): string;
begin
  Result := aDataIn.ID1.ToString            + cSeparator;
  Result := Result +  aDataIn.S1            + cSeparator;
  Result := Result +  BoolToStr(aDataIn.B1) + cSeparator;
  Result := Result +  aDataIn.S2            + cSeparator;
  Result := Result +  aDataIn.C1            + cSeparator;
  Result := Result +  aDataIn.S3;
end;

OK, this is now slower:

PrepareLineForExport: 1358 ms (single expression using + )

PrepareLineForExport2: 2242 ms

 

I realize this is probably the most basic thing for most of you, for me this is something really new.

 

function PrepareLineForExport2(const aDataIn: TData): string;
begin
  Result :=    aDataIn.ID1.ToString            
             +     cSeparator 
             + aDataIn.S1            
             +     cSeparator
             + BoolToStr(aDataIn.B1)
             +     cSeparator
             + aDataIn.S2
             +     cSeparator
             +  aDataIn.C1
             +     cSeparator
             +  aDataIn.S3
             ;
end;

Sometimes I like to use a "prefix" pattern like this.

To make things visually more readble, and to easily include/exclude parts for testing ( by puttin // in frontt).

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×