I have an algorithm written in PHP which communicates with MySQL. On standard shared hosting server it takes about ~5 seconds to calculate. My question is – how can I speed it up (of course without changing the algorithm itself), use dedicated/VPS, maybe some cloud computing or…?
What are your suggestions?
EDIT: It’s Dijkstra algorithm for public transport. I have (only) 3500 unique stops.
In short – I have multiple arrays for recording active stops, previous stops, lineToStop, totalTime, travelingTime and so on. I loop for number of stops, get an id of a stop, build connections to other stops (based on the time on that active stop), loop again for size of stops() to find the one with the lowest value, mark it as active and continue again.
I realized it’s optimizatio problem so – > Dijkstra algorithm optimization/caching
When you buy an airline ticket, the first question is not “where do you want to go?” – it is “where are you going from?” In other words, without much, much, MUCH more detail, we’re just guessing.
The surest answer for “How can I speed it up?” in any case is this:
Measure it, find actual bottlenecks, remove bottlenecks, repeat until it runs well enough.
Without profiling, you could waste endless hours on optimizing some part of the code that doesn’t have any significant performance impact (Note the emphasis on “actual bottlenecks” – many programmer-centuries were spent optimizing what someone imagined might be the bottleneck).
Example: speeding up a method by 1000% is pointless, if it’s a method that gets called once at the start of your program, and the program spends 90% of its time waiting for disk I/O. Another example: making a disk array to help with I/O bottlenecks, when the program spends 90% of the time waiting for the SQL server which runs a complex, unindexed query. Those are not the only problems you could encounter, and they aren’t even mutually exclusive – but you need to know what problems you have before you start solving one. “It is slow” is not a description of a problem, it is just a symptom (just like “a headache” can be a symptom of 9000 different medical conditions).
TL;DR: There is no silver bullet.