I'm writing several performace benchmarks mainly to compare the performance of cross-platform tools. One of these is a native implementation of bubble sort in Swift.
I've implemented it as folows:
do{ swapped = false for (var i = 1; i < testSize; i++){ if (sortArray[i-1] > sortArray[i]){ temp = sortArray[i-1] sortArray[i-1] = sortArray[i] sortArray[i] = temp swapped = true } } }while(swapped == true) Running this for an array of 2500 takes almost 20 seconds on an iphone 4s.
That's hilariously slow. I've implemented the same piece of code using cordova (javascript) and that only takes 2 seconds.
I've also found results of the same test in objective c tested back in 2012 and back then the native time was about 0.6 seconds.
Doing an input validation benchmark also returned comparable results.
Now I'm trying to find out why this is.
Is it because I implemented it incorrectly?
Or is Swift not optimized yet for this type of actions?
Or is it simply because Swift is not optimized for older devices like the iPhone 4s?
Or is it still something else?