Solved

AnsiString manipulation extremelly slow (D2009)

Posted on 2008-10-18
3
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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