Dont compare specs, iOS on iPhone is super optimized. Till last year iPhone had only 1 GB RAM and yet all apps were running well.
Unlike in Android more RAM, CPU is required for better experience.
Apple devices sell well not because of best hardware specs but because of user experience and ease of use. Even in Android world you will find best specs but poor user experience phone. So having best specs really doesnt mean best user experience.