Daily iOS
CS fundamentals and algorithms

Cache locality

You iterate over 100,000 coordinates and sum distances. Between these two versions, what's the main reason A is noticeably faster than B?

struct P { var x, y: Double }   // A: [P]
final class Q { var x, y: Double } // B: [Q]

Pick one

Submit