+ 3
Javascript queue
Javascript array "shift" function do same thing like dequeue, but it rearange indexes of whole array, so "shift" has O(n) time comlexity. For that reason I implement simple js queue with O(1) time complexity of enqueuing and dequeing. My question is: when I run code in the computer browser everything is ok (my queue is 100 times faster than js array), but when I run this code in sololearn mobile app js array is fast as my queue. Any ideas why this happens. https://code.sololearn.com/WourTXDqzF04/?ref=app
2 Answers
+ 6
Implementations of built-in functionnalities depend on each browsers JS engine, as well as devices specific optimizations (mobile devices could have been better optimized than desktop PC to prevent laking of absolute power for example), and you cannot be sure of efficiency of each of them: optimizing JS for each device/browser combinations is not a realistic task and should be an impossible headhache ^^
+ 6
My results: you 48ms them 9116ms