Cocoa graphics speed
Cocoa graphics speed
- Subject: Cocoa graphics speed
- From: John Nairn <email@hidden>
- Date: Mon, 29 Sep 2003 15:05:08 -0600
The drawRect method of my custom view draws many elements (100's to
100,000) and each element has a stroke method. Drawing these elements
is twice as slow in Cocoa app then in prior version of the app in
Carbon. But it is much worse --- most of the graphics time in Cocoa is
taken by filling a rectangle with a color and that graphics call
(NSRectFill()) is TEN times slower than the comparable Carbon
FillRect(). Is there any way to speed up graphics in Cocoa?
Here is the central, slow method in Cocoa app
- (void)stroke:(id)sender
{
float radius=[sender radius];
NSRect ptRect;
[color set]; // color for element
ptRect=NSMakeRect((float)pt.x-radius,(float)pt.y-radius, 2.*radius,
2.*radius);
NSRectFill(ptRect);
}
The Carbon code that is 10 times faster (despite needing extra
calculation - a conversion to pixel coordinates) is:
void MatPoint2D::DrawPoint(RGBColor *pc,int thisRad)
{
int xpix,ypix;
Pattern qd;
RGBForeColor(pc);
XYtoPix(pos.x,pos.y,&xpix,&ypix); // convert position to pixels
SetRect(&tempRect,xpix-thisRad,ypix-thisRad,
xpix+thisRad+1,ypix+thisRad+1);
FillRect(&tempRect,GetQDGlobalsBlack(&qd));
}
Here is summary are one experiment of many plots
Spool data from files: Cocoa - 8.9 sec Carbon - 9.0 sec
Fill Rectangles: Cocoa - 17.9 sec Carbon - 1.8 sec
Other stuff: Cocoa - 0.5 secs Carbon - 1.0 sec
Total time: Cocoa - 27.3 secs Carbon - 12.8 sec
Thus Carbon and Cocoa are identical except in NSFillRect() vs
FillRect() which differ by factor of 10?
------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.eng.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.