Solved

AnsiString manipulation extremelly slow (D2009)

Posted on 2008-10-18
3
250 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
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…

707 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

13 Experts available now in Live!

Get 1:1 Help Now