I recently started doing a lot more coding, and even more recently bought an iPad Pro 9.7-inch. Out of curiosity, I wrote a quick-and-dirty program to benchmark single-core performance on my different devices. It's simple - it runs through the numbers 0 - 100,000, checking if they're prime, and measures the time it takes to run. It's quite possible I've made a mistake in the program - mathematical or logical - but it doesn't really matter as long as it's consistent, since I'm not actually looking for prime numbers. It isn't a particularly efficient way of looking for primes either, but again, that doesn't really matter here.
The devices I tested were: - an i7 2600-based Hackintosh (16GB RAM, running El Capitan) - an i7 4850HQ-based 15-inch MacBook Pro (16GB RAM, running El Capitan) - a Surface Pro 3 i3 (4GB RAM, running Windows 10) - an iPhone 6S Plus (2GB RAM, running iOS 9.3) - an iPad Pro 9.7-inch (2GB RAM, running iOS 9.3) - an iPad 2 (iOS 9.3, because why not)
For the iOS devices I wrote the program in Swift (which is what I've been primarily coding in lately). For the Surface and Macs, I used C++. I initially tried running the Swift version on the Macs, but used the C++ version in the end. For some reason the Swift version took much longer to run on the Macs. Something on the order of 50-65 seconds. I presume I overlooked some optimisation or compiler setting. 1
Here are the times (and a ratio of how they compare to the top result): * 18.814 seconds - 1.00x - i7 2600 Desktop * 20.350 seconds - 0.92x - i7 4850HQ MacBook Pro * 21.499 seconds - 0.88x - iPad Pro 9.7-inch * 25.815 seconds - 0.73x - iPhone 6S Plus * 40.654 seconds - 0.46x - i3 Surface Pro 3 * 281.21 seconds - 0.07x - iPad 2
The results are pretty interesting. The iPad performs extremely well against the desktop and laptop considering the differences between the devices in terms of size, power consumption etc. Geekbench single-core results jibe fairly well with my results; I got a score of 3151 for the desktop vs 3041 for the iPad.2 The Surface comes in at about half the speed of the iPad Pro, which is also surprising. While iPad Pro feels a lot faster than the Surface in general use like web browsing, my gut feeling had been that x86 would still beat ARM. It's interesting to see about 13x improvement over the iPad 2. Without putting too much stock in what is a pretty artificial benchmark, the iPad obviously has a fair bit of grunt. I'm hoping more 'pro' apps will appear over time, letting it take up more of the functionality of a laptop or desktop, if it ostensibly has the power to do it. Here's the source code for the Swift and C++ versions of PrimeChecker, if anyone wants to give them a shot. They may need a little tweaking depending on what you want to run them on. Update: There have been quite a few suggestions for how the code could be optimised. Checking the range 2..<sqrt(n)+1, and avoiding writing the prime bool excessively do indeed vastly improve performance. However, as I said in the intro, it doesn't really matter for my purposes; I'm not trying to find primes faster, I'm just looking to run comparable code on each device. For curiosity's sake, after adding in those optimisations it takes ~7.6 seconds to find all the primes between 1 and 100,000,000 on the desktop, ~8.4 on the iPad and ~10.3 seconds on the iPhone (larger range just to get more palpable numbers). The optimised code gives a set of results in a pretty similar ratio to the unoptimised code.
I tried keeping the two versions as close to each other as possible, though I'm not entirely sure what sort of difference in overhead there may be between the Swift and C++ code. I ran the program three times on each device, and got the averages.For the most part, each time was within 0.2 seconds of the others anyway. ↩︎
My desktop gets a multi-core score of 12,050 vs the iPad's 5,215. Quite a big difference, ~2.3x, though that's pitting four (hyper-threaded) cores against two. ↩︎