I did some playing around with raw Cocoa APIs and got some interesting and unexpected results. The attached zip is my modifications, with a couple of different versions implemented. Only one is enabled at a time; you'll need to adjust what's commented out to see the variations.
Timings on my system (MacBook 2012, macOS 10.13.8):
TCanvas.TextOut:
* Black fg, bsClear bg: 90ms
* Random fg, bsClear bg: 216ms
* Random fg/bg color: 300ms
NSString.drawAtPoint_withAttributes:
* No fg/bg color: 50ms
* Random fg color: 63ms
* Random fg/bg color: 260ms
NSAttributedString.drawAtPoint:
* No fg/bg color: 52ms
* Random fg color: 68ms
* Random fg/bg color: 264ms
* Random fg, NSRectFill for bg: 100ms
* Single random fg/bg color, created at loop start: 240ms
* Single random fg created at loop start, NSRectFill for bg: 87ms
NSTextStorage/NSLayoutManager (created at top of loop and cached):
* No fg/bg color: 43ms
* Random fg color: 170ms
* Random fg/bg color: 230ms
* Random fg/bg set once outside loop: 61ms
* Update with new NSAttributedString, random fg/bg: 235ms
Windows 10 TCanvas.TextOut:
* Black fg, bsClear bg: 40-60ms
* Random fg/bg: 31-47ms
The NSTextStorage/NSLayoutManager "Random fg/bg color" case (230ms) is essentially what's implemented by LCLCocoa's TCanvas.TextOut. The idea is that the string is set/decoded into font glyphs once then cached, and then setting the foreground/background color just updates the drawing. Based on my understanding of the various APIs, I would have expected that to be the fastest.
Relying on the text apis to do the background fill is extremely slow, and again, I'm not sure why. Replacing the background with a simple NSRectFill dramatically speeds things up. The one exception is when using NSTextStorage with a single cached foreground/background, which is fast. Aside from that case, the fastest looks to be NSAttributedString with a separate NSRectFill call.
Moving the for loop to only enclose NS(Attribute)String creation/painting, so the context saving/restoring is only done once improves things by 5-10ms, but that's probably not possible in the general case.
It might be possible to get faster speed for the random foreground color using CoreText, but I haven't tested that, and you'd need to dig down a few layers for it. CTLine are created from an NSAttributedString and CTLineDraw uses the foreground color it has, so using that won't gain anything. Using CTRunDraw or whatever the direct glyph drawing function is might allow more control.
There's a commented out block in CreateWnd that might be worth testing in your more complicated apps. It tells the system that the app doesn't use HDR color spaces, and was suggested by one of our customers based on a similar patch in LibreOffice. In the sample app it doesn't change the speed, but in Beyond Compare it noticably improved resize speed on 4K+ monitors. We're still evaluating it, so I can't promote it as a patch just yet.
The attached patch is almost certainly wrong and definitely needs cleanup, but adds an optimized NSAttributedString + NSRectFill path to TCocoaContext.TextOut which improves performance of the benchmark by about 50%. I have not tested it outside the benchmark.