Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

AnsiString manipulation extremelly slow (D2009)

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
bryan7
Asked:
bryan7
1 Solution
 
wd123Commented:
in delphi 2009 all string is widestring ...
0
 
bryan7Author Commented:
that doesn't explain what's wrong with the 1st test
0
 
ChristianWimmerCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now