let stopwatch = Stopwatch.createStarted()
if text.length != 0 {
text.draw(with: textRect, options: .usesLineFragmentOrigin, context: nil)
}
print("stopwatch \(stopwatch.stop().toString())")
结果:
stopwatch 0.0241029262542725 s
stopwatch 0.0221379995346069 s
stopwatch 0.00433492660522461 s
stopwatch 0.00229907035827637 s
stopwatch 0.00661897659301758 s
stopwatch 0.00540506839752197 s
stopwatch 0.0047069787979126 s
stopwatch 0.00523698329925537 s
stopwatch 0.0541820526123047 s
text.draw
需要50毫秒。
有没有办法优化NSAttributedString.draw
的性能?
这是NSAttributedString
。