I implement complex algorithm with PHP and mysql. I noticed that to display main page, it takes about 1.8sec or more... Is it too slow?
It depends upon your mysql queries. You can run each query in phpmyadmin, note the time and add it up. This way you will also know which query is taking longer and needs optimisation
The queries are time consuming. Try minimizing their number or maybe using Ajax so that you can load the page first and load the data second.
Thanks NoamBarz, Actually i am worried about this site: quick-name-generator.com. I takes about 1.5s to load main page as it is algorithmically intensive. Until now i havent found a way, although i have tried my best to optimize.
olddocks, are all names pregenerated and stores in database? Or you generate Markov chains in real time?
Tweak the code to debug SQL queries; dump them all to file for a single page load. Then, go over each one and see how it can be optimized and/or combined with others.
So, if you will pregenerate a some chains, your page will generates more faster. But i think it is not what you want to hear.
very good idea indeed. The problem is if i pre-generate the outcomes, there will be a large no of random words stored in database. Again if i want to pick randomly rand() in mysql would drastically face slowdowns. Further the pre-generated ones may occur frequently in outcomes. I will see what i can do. +rep added
Hm. Generete random number via php ($rand=mt_rand(1,$max)) and make select query like: select * from table where `id`='$rand'; And if `ID` is primary key it will work very fast. If you need another field in 'where' build index with it.
Agree with you that "order by Rand()" is pretty slow in MySQL. One thing I saw on your page for baby's first name: popular name was "Sage" and randomly twisted was "Sage". You might want to check that these are not equal. Cool site though