Solved

AnsiString manipulation extremelly slow (D2009)

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 8 hours left to enroll

634 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