wincen Posted February 20, 2008 Share Posted February 20, 2008 What are the pros and cons of calculating distance from lat/lons in php vs calculating it in mysql? I've been searching online and it appears that both are able to do so, but I have yet to find which is the preferred method. Does one offer more accuracy? Is it faster to do so in mysql and just return the distance? Quote Link to comment Share on other sites More sharing options...
dave420 Posted February 20, 2008 Share Posted February 20, 2008 I would suggest doing some benchmarking of the two different methods, and see which one is fastest. They're both going to be as accurate as each other, so it comes down to speed. Calculate a bunch of different distances in both methods and see which one returns fastest, then use that. Quote Link to comment Share on other sites More sharing options...
Sulman Posted February 20, 2008 Share Posted February 20, 2008 I have done this with PHP and MS SQL sproc (not MySQL). To be honest I didn't see much difference but I never benchmarked so daves suggestion above is a good way to go. Quote Link to comment Share on other sites More sharing options...
wincen Posted February 20, 2008 Author Share Posted February 20, 2008 How do you run benchmarks on these calculations? I've never done so and am curious to see the results. Does anyone have tools they can suggest? Thanks! Quote Link to comment Share on other sites More sharing options...
revraz Posted February 20, 2008 Share Posted February 20, 2008 If it happens so fast you can't see the difference, then does it matter? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 20, 2008 Share Posted February 20, 2008 How do you run benchmarks on these calculations? I've never done so and am curious to see the results. Does anyone have tools they can suggest? Thanks! <?php $t1 = microtime(true); for($i=0; $i < 100; $i++) { // do method 1 } $t2 = microtime(true); for($i=0; $i < 100; $i++) { // do method 2 } $t3 = microtime(true); echo "Method 1 took ", $t2-$t1, '<br/>'; echo "Method 2 took ", $t3-$t2, '<br/>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.