Quick question, has anyone done a benchmark on random number generation between javascript and php? I’m not talking about 4-5 random function calls but on a large scale, I’m more interested about speed rather than better random numbers.
Quick question, has anyone done a benchmark on random number generation between javascript and
Share
As Alan pointed out, the performance of JavaScript’s random numbers depends on the resources the client-side brings to the party. However, there are a few more things to consider:
Since you’re looking for random numbers, generated on a large scale, it is important to note that browsers may stop your JavaScript from reaching the end of a loop. Some browsers might assume the script contains a deadlock somewhere and ask the user to stop or debug the script.
In addition to this, the numbers will only be generated as long as the client is on the page and has JavaScript enabled.
On PHP, there are two things to consider (apart from server hardware). If you’re really planning on generating vast quantities of random numbers, the response to your client will be slowed down, too. Though PHP is faster then JavaScript (by far), it’s no good to have your visitors wait too long for a response from the server.
A possible solution might be to send the response out anyway and get the randomly generated numbers via ajax. Downside here is: you’ve lost the speed benefit of php.
In your situation, I’d keep the random generator server side. Perhaps look into other languages to put together a little C programme if you’re really focused on speed and server load (PHP is resource expensive). But sticking to the tags, again: stick to php – after all, quite a lot of it is C anyways…