Solved

AnsiString manipulation extremelly slow (D2009)

Posted on 2008-10-18
3
251 Views
Last Modified: 2010-04-05
Is this normal???
// ansistring test
 

Var a: ansistring;

    b: integer;
 

 PerfTimerInit;

 for b:= 0 to 50000 do

  a:= a+chr(random(256));

 caption:= inttostr(PerfTimerStop);

 // 3977 ms
 
 
 
 

// string test
 

Var a: string;

    b: integer;
 

 PerfTimerInit;

 for b:= 0 to 50000 do

  a:= a+chr(random(256));

 caption:= inttostr(PerfTimerStop);

 // 2ms
 
 
 
 
 

Uses Windows;
 

    procedure PerfTimerInit;

    function PerfTimerStop: Integer;
 

Var     PF, PC0, PC1: Int64;
 

implementation
 

procedure PerfTimerInit;

begin

   QueryPerformanceFrequency(PF);

   QueryPerformanceCounter(PC0);

end;
 

function PerfTimerStop: Integer;

begin

    QueryPerformanceCounter(PC1);

    Result:= ((PC1-PC0)*1000) div PF

end;

Open in new window

0
Comment
Question by:bryan7
3 Comments
 
LVL 5

Expert Comment

by:wd123
ID: 22747642
in delphi 2009 all string is widestring ...
0
 
LVL 3

Author Comment

by:bryan7
ID: 22747649
that doesn't explain what's wrong with the 1st test
0
 
LVL 6

Accepted Solution

by:
ChristianWimmer earned 25 total points
ID: 22763054
Chr returns a widechar which is converted to ansichar with a call to WideCharToMultiByte. At least I would believe this. The CPU window should confirm or deny it.
btw: String is a UnicodeString, not a WideString. US is unlike to WS reference counted as old String. WS is for COM support which uses BSTR.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now