 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Hartmut Kloppert Guest
|
Posted: Tue May 10, 2005 1:10 pm Post subject: Performance problem with new PC |
|
|
My BCB4 application is running fine under Windows-ME.
On my new faster machine with Windows-XP, however,
the 'draw' and 'floodfill' perfomance is very bad.
I boiled it down to a small simple test case:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <process.h>
#pragma hdrstop
#include "SxTrace.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TCanvas *gCanvas;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
Trace(INI," ");
DrawGrid1->ColCount=10;
DrawGrid1->RowCount=10;
for(int c=0;c<DrawGrid1->ColCount;c++) DrawGrid1->ColWidths[c]=57;
for(int r=0;r<DrawGrid1->RowCount;r++) DrawGrid1->RowHeights[r]=36;
gCanvas = DrawGrid1->Canvas;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TColor CColor;
Trace(0,"Start Draw from ImageList");
ImageList1->Draw(DrawGrid1->Canvas,Rect.Left,Rect.Top,0,true);
Trace(0,"End of Draw from ImageList");
CColor=gCanvas->Pixels[Rect.Left+27][Rect.Top+10];
gCanvas->Brush->Color=clLime;
Trace(0,"Start FloodFill");
gCanvas->FloodFill(Rect.Left+27,Rect.Top+10,CColor,fsSurface);
Trace(0,"End FloodFill");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Trace(FINI," ");
Sleep(100);
execlp("NOTEPAD.EXE","NOTEPAD.EXE","SxTrace.txt",NULL);
Sleep(100);
Application->Terminate();
}
//---------------------------------------------------------------------------
Don't get confused with the 'Trace' function. It runs a trace in memory
with performance-counter generated time-stamps. At application's end
the trace data is moved into a readable txt-file.
The result is:
Windows-ME: Draw from ImageList takes < 0.09 ms
FloodFill approx. 0.3 ms
The 100 Drawgrid-fields show up at once!
Windows-XP: Draw from ImageList takes approx. 2.2 ms
FloodFill approx. 28 ms
The 100 Drawgrid-fields take 3 sec to show up!
What am I doing wrong? What changes have to be done to the application
or to Windows-XP to make it run as before?
Harry
[email]HKloppert (AT) access-4-free (DOT) com[/email]
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue May 10, 2005 4:40 pm Post subject: Re: Performance problem with new PC |
|
|
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote
I would not recommend using a global pointer to the Canvas. It is not
needed anyway, you can query the current Canvas each time the OnDrawCell
event is triggered.
| Quote: | DrawGrid1->ColCount=10;
DrawGrid1->RowCount=10;
for(int c=0;c<DrawGrid1->ColCount;c++) DrawGrid1->ColWidths[c]=57;
for(int r=0;r<DrawGrid1->RowCount;r++)
DrawGrid1->RowHeights[r]=36; |
You can set the DefaultColWidth and DefaultRowHeight properties before
adding your new cells. Then they are sized appropriately when they are
added and you don't have to resize them afterwards.
| Quote: | CColor=gCanvas->Pixels[Rect.Left+27][Rect.Top+10];
|
Since you are drawing the same image over and over, you can speed this up by
pre-caching the color value that you are going to draw. Then you don't have
to re-query it each time. The Pixels property is notoriously slow.
| Quote: | gCanvas->FloodFill(Rect.Left+27,Rect.Top+10,CColor,fsSurface);
|
Why not just fill in the area in the original image statically one time and
display it as-is, rather than filling it dynamically every time the event is
triggered?
| Quote: | Application->Terminate();
|
You don't need to call that. When the MainForm is closed, it already calls
that automatically.
Gambit
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Wed May 11, 2005 6:40 pm Post subject: Re: Performance problem with new PC |
|
|
Thank you, Gambit, for the recommendations. They definetly
will optimize the code. However, they do not address the
real problem because the code was a "boiled down" version
of the real application:
There I have to floodfill an area on the DrawGrid1->Canvas
with different colors depending on external conditons. And
since I don't know the current color of that area I first have
to get it thru
CColor=DrawGrid1->Canvas->Pixels[Rect.Left+27][Rect.Top+10];
and then recolor it thru
DrawGrid1->Canvas->FloodFill(Rect.Left+27,Rect.Top+10,CColor,fsSurface);
And "FloodFill" seems to be the bottleneck. It takes approx. 29 ms on my
new faster computer compared to 0.3 ms on the older one.
The differents on both computers are:
Old: Pentium III, 1 GHz, Windows-ME
New: AMD Athlon 64 3000+, Windows-XP
May be I have a hardware problem on my new computer?
In order to have you and others have a quick test on the perfomance
of the test-application I have put it to the attachments-group. Just copy
it to a test-folder, let it run and check the timings in the trace-file that
will be displayed after termination.
Thanks,
Hartmut
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote in message
news:4280b346 (AT) newsgroups (DOT) borland.com...
TCanvas *gCanvas;
I would not recommend using a global pointer to the Canvas. It is not
needed anyway, you can query the current Canvas each time the OnDrawCell
event is triggered.
DrawGrid1->ColCount=10;
DrawGrid1->RowCount=10;
for(int c=0;c<DrawGrid1->ColCount;c++)
DrawGrid1->ColWidths[c]=57;
for(int r=0;r<DrawGrid1->RowCount;r++)
DrawGrid1->RowHeights[r]=36;
You can set the DefaultColWidth and DefaultRowHeight properties before
adding your new cells. Then they are sized appropriately when they are
added and you don't have to resize them afterwards.
CColor=gCanvas->Pixels[Rect.Left+27][Rect.Top+10];
Since you are drawing the same image over and over, you can speed this up
by
pre-caching the color value that you are going to draw. Then you don't
have
to re-query it each time. The Pixels property is notoriously slow.
gCanvas->FloodFill(Rect.Left+27,Rect.Top+10,CColor,fsSurface);
Why not just fill in the area in the original image statically one time
and
display it as-is, rather than filling it dynamically every time the event
is
triggered?
Application->Terminate();
You don't need to call that. When the MainForm is closed, it already
calls
that automatically.
Gambit
|
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Wed May 11, 2005 6:47 pm Post subject: Re: Performance problem with new PC |
|
|
Hartmut Kloppert wrote:
| Quote: | And "FloodFill" seems to be the bottleneck. It takes approx. 29 ms on my
new faster computer compared to 0.3 ms on the older one.
May be I have a hardware problem on my new computer?
|
What do you call a faster computer ? Maybe your new computer has
a slow graphics card.
Hans.
|
|
| Back to top |
|
 |
Jonathan Benedicto Guest
|
Posted: Wed May 11, 2005 6:54 pm Post subject: Re: Performance problem with new PC |
|
|
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote
| Quote: |
In order to have you and others have a quick test on the perfomance
of the test-application I have put it to the attachments-group. Just
copy
it to a test-folder, let it run and check the timings in the
trace-file that
will be displayed after termination.
|
I have a Celeron P3 1.2 Ghz, Win XP Home, Intel 82810E, 256MB RAM, and
this is a sample of what the trace file looked like on my computer:
00000056.5<056.5>: Start Draw from ImageList
00000057.1<000.6>: End of Draw from ImageList
00000057.2<000.0>: Start FloodFill
00000102.5<045.3>: End FloodFill
00000102.8<000.3>: Start Draw from ImageList
00000103.4<000.6>: End of Draw from ImageList
00000103.5<000.1>: Start FloodFill
00000136.7<033.2>: End FloodFill
00000136.8<000.1>: Start Draw from ImageList
00000137.5<000.7>: End of Draw from ImageList
00000137.6<000.1>: Start FloodFill
00000171.5<034.0>: End FloodFill
00000171.7<000.1>: Start Draw from ImageList
00000172.3<000.7>: End of Draw from ImageList
00000172.4<000.1>: Start FloodFill
00000205.3<032.9>: End FloodFill
Jonathan
|
|
| Back to top |
|
 |
Jonathan Benedicto Guest
|
Posted: Wed May 11, 2005 6:55 pm Post subject: Re: Performance problem with new PC |
|
|
"Hans Galema" <notused (AT) notused (DOT) nl> wrote
| Quote: |
What do you call a faster computer ? Maybe your new computer has
a slow graphics card.
|
Isn't GDI processsed by the CPU ?
Jonathan
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Wed May 11, 2005 10:40 pm Post subject: Re: Performance problem with new PC |
|
|
How do I know?
Hartmut
"Jonathan Benedicto" <incorrect (AT) no (DOT) server> wrote
| Quote: | Isn't GDI processsed by the CPU ?
Jonathan
|
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Wed May 11, 2005 10:51 pm Post subject: Re: Performance problem with new PC |
|
|
Yes, I thought about the graphics card too.
The new (faster) computer has a
NVIDIA GeForce4 440 Go 64 MB
compared to the (slower) machine which has a
SIS 630/730 16MB shared
I'm not an expert on this, but assumed that the newer (faster)
machine is state of the art from HP while the other one is
4 years old.....
Hartmut
"Hans Galema" <notused (AT) notused (DOT) nl> wrote
| Quote: | What do you call a faster computer ? Maybe your new computer has
a slow graphics card.
Hans.
|
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Wed May 11, 2005 11:21 pm Post subject: Re: Performance problem with new PC |
|
|
Jonathan, thanks for running the "benchmark".
Aha, on your machine it takes even longer to do the floodfill
All 100 fields need approx. 3 to 4 seconds to get
displayed. (The first number on the trace is the elapsed
time, the second number in <> the difference to the last
entry, all in milliseconds)
My machine (AMD 64 Athlon 3000+; NVIDIA-grahic; Win-XP) yields
00000015.8<015.8>: Start Draw from ImageList
00000018.1<002.2>: End of Draw from ImageList
00000018.1<000.0>: Start FloodFill
00000046.5<028.4>: End FloodFill
00000046.6<000.1>: Start Draw from ImageList
00000048.8<002.2>: End of Draw from ImageList
00000048.8<000.0>: Start FloodFill
00000077.0<028.2>: End FloodFill
.....always slow.
Total time to display all fields: 3126 ms
The old computer (P3 1GHz; SIS-graphic; Win-ME) showes
00000010.1<010.0>: Start Draw from ImageList
00000010.2<000.1>: End of Draw from ImageList
00000010.5<000.3>: Start FloodFill
00000041.6<031.1>: End FloodFill
00000041.7<000.1>: Start Draw from ImageList
00000041.8<000.0>: End of Draw from ImageList
00000041.8<000.1>: Start FloodFill
00000042.1<000.3>: End FloodFill
00000042.1<000.0>: Start Draw from ImageList
00000042.2<000.0>: End of Draw from ImageList
00000042.2<000.1>: Start FloodFill
00000042.5<000.3>: End FloodFill
....one time slow and then always fast (out of the cache?)
Total time to display all fields: 73 ms
and I have a third (old) machine (P3 600MHz; 64MB;
standard PCI Graphics adapter (VGA), WIN-9 it showes
00000014.5<014.4>: Start Draw from ImageList
00000017.1<002.6>: End of Draw from ImageList
00000017.1<000.0>: Start FloodFill
00000037.4<020.3>: End FloodFill
00000038.4<001.0>: Start Draw from ImageList
00000040.8<002.5>: End of Draw from ImageList
00000040.8<000.0>: Start FloodFill
00000041.1<000.3>: End FloodFill
00000041.3<000.2>: Start Draw from ImageList
00000043.7<002.4>: End of Draw from ImageList
00000043.7<000.0>: Start FloodFill
00000044.9<000.2>: End FloodFill
....same as above, one slow and then fast. Total time
to display all fields: 226 ms.
One possible conclusion: as soon as WIN-XP is involved
it becomes slow! Why?
Hartmut
"Jonathan Benedicto" <incorrect (AT) no (DOT) server> wrote
| Quote: | I have a Celeron P3 1.2 Ghz, Win XP Home, Intel 82810E, 256MB RAM, and
this is a sample of what the trace file looked like on my computer:
00000056.5<056.5>: Start Draw from ImageList
00000057.1<000.6>: End of Draw from ImageList
00000057.2<000.0>: Start FloodFill
00000102.5<045.3>: End FloodFill
00000102.8<000.3>: Start Draw from ImageList
00000103.4<000.6>: End of Draw from ImageList
00000103.5<000.1>: Start FloodFill
00000136.7<033.2>: End FloodFill
00000136.8<000.1>: Start Draw from ImageList
00000137.5<000.7>: End of Draw from ImageList
00000137.6<000.1>: Start FloodFill
00000171.5<034.0>: End FloodFill
00000171.7<000.1>: Start Draw from ImageList
00000172.3<000.7>: End of Draw from ImageList
00000172.4<000.1>: Start FloodFill
00000205.3<032.9>: End FloodFill
Jonathan
|
|
|
| Back to top |
|
 |
Jonathan Benedicto Guest
|
Posted: Thu May 12, 2005 5:27 am Post subject: Re: Performance problem with new PC |
|
|
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote
I think that GDI calls are handled by the CPU, so a different graphics
card shouldn't make any difference. I think that the speed difference
is caused by the new XP GDI, and that you'd have to use GDI+ to get
any faster.
Jonathan
|
|
| Back to top |
|
 |
zegi Guest
|
Posted: Thu May 12, 2005 9:34 am Post subject: Re: Performance problem with new PC |
|
|
Hi Hartmut
Try to use the API Command
BOOL FloodFill(
HDC hdc, // handle to device context
int nXStart, // x-coordinate, where fill begins
int nYStart, // y-coordinate, where fill begins
COLORREF crFill // fill color
);
::FloodFill(gCanvas->Handle,......
zegi
Hartmut Kloppert schrieb:
| Quote: | My BCB4 application is running fine under Windows-ME.
On my new faster machine with Windows-XP, however,
the 'draw' and 'floodfill' perfomance is very bad.
I boiled it down to a small simple test case:
//---------------------------------------------------------------------------
#include <vcl.h
#include
#pragma hdrstop
#include "SxTrace.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TCanvas *gCanvas;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
Trace(INI," ");
DrawGrid1->ColCount=10;
DrawGrid1->RowCount=10;
for(int c=0;c<DrawGrid1->ColCount;c++) DrawGrid1->ColWidths[c]=57;
for(int r=0;r<DrawGrid1->RowCount;r++) DrawGrid1->RowHeights[r]=36;
gCanvas = DrawGrid1->Canvas;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TColor CColor;
Trace(0,"Start Draw from ImageList");
ImageList1->Draw(DrawGrid1->Canvas,Rect.Left,Rect.Top,0,true);
Trace(0,"End of Draw from ImageList");
CColor=gCanvas->Pixels[Rect.Left+27][Rect.Top+10];
gCanvas->Brush->Color=clLime;
Trace(0,"Start FloodFill");
gCanvas->FloodFill(Rect.Left+27,Rect.Top+10,CColor,fsSurface);
Trace(0,"End FloodFill");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Trace(FINI," ");
Sleep(100);
execlp("NOTEPAD.EXE","NOTEPAD.EXE","SxTrace.txt",NULL);
Sleep(100);
Application->Terminate();
}
//---------------------------------------------------------------------------
Don't get confused with the 'Trace' function. It runs a trace in memory
with performance-counter generated time-stamps. At application's end
the trace data is moved into a readable txt-file.
The result is:
Windows-ME: Draw from ImageList takes < 0.09 ms
FloodFill approx. 0.3 ms
The 100 Drawgrid-fields show up at once!
Windows-XP: Draw from ImageList takes approx. 2.2 ms
FloodFill approx. 28 ms
The 100 Drawgrid-fields take 3 sec to show up!
What am I doing wrong? What changes have to be done to the application
or to Windows-XP to make it run as before?
Harry
[email]HKloppert (AT) access-4-free (DOT) com[/email]
|
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Thu May 12, 2005 11:59 pm Post subject: Re: Performance problem with new PC |
|
|
Hi zegi,
I'm assuming that is waht BCB is using internally.
Anyway, I was not in a postion to get it to work.
Could you show the source of a simple app where
just an e.g. black Form is filled with another color?
By using the API-function.
Hartmut
"zegi" <zegis (AT) hotmail (DOT) com> wrote
| Quote: | Hi Hartmut
Try to use the API Command
BOOL FloodFill(
HDC hdc, // handle to device context
int nXStart, // x-coordinate, where fill begins
int nYStart, // y-coordinate, where fill begins
COLORREF crFill // fill color
);
::FloodFill(gCanvas->Handle,......
zegi
|
|
|
| Back to top |
|
 |
Hartmut Kloppert Guest
|
Posted: Fri May 13, 2005 12:03 am Post subject: Re: Performance problem with new PC |
|
|
How do I do this?
"Jonathan Benedicto" <incorrect (AT) no (DOT) server> wrote
| Quote: | "Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote in message
news:4282944e (AT) newsgroups (DOT) borland.com...
How do I know?
I think that GDI calls are handled by the CPU, so a different graphics
card shouldn't make any difference. I think that the speed difference is
caused by the new XP GDI, and that you'd have to use GDI+ to get any
faster.
Jonathan
|
|
|
| Back to top |
|
 |
Jonathan Benedicto Guest
|
Posted: Fri May 13, 2005 12:24 am Post subject: Re: Performance problem with new PC |
|
|
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote
Well, I have never used GDI+, and I've always found GDI to be fast
enough. Can't you use Canvas->Rectangle or Ellipse or something other
than FloodFill to draw the graphics ?
Jonathan
|
|
| Back to top |
|
 |
Jonathan Benedicto Guest
|
Posted: Fri May 13, 2005 12:26 am Post subject: Re: Performance problem with new PC |
|
|
"Hartmut Kloppert" <HKloppert (AT) access-4-free (DOT) com> wrote
| Quote: |
I'm assuming that is waht BCB is using internally.
Anyway, I was not in a postion to get it to work.
Could you show the source of a simple app where
just an e.g. black Form is filled with another color?
By using the API-function.
|
I checked the VCL code, and yes they just about directly call the API
function. So, you shouldn't get any performance improvement using it.
Jonathan
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|