From: Tamara Temple Date: 2013-06-05T09:53:22+09:00 Subject: Re: Ruby extremely slow compared to PHP Mick Jagger wrote: > Tamara Temple wrote in post #1111074: > > So, basically, curl is getting a lot less data than Net::HTTP is > > getting. I haven't delved into why this is so, but these are interesting > > stats: > > > > > > This is for the ruby version: > > > > Total fetch time: 28 seconds. > > Total fetch size: 1954452 bytes. > > > > real 0m28.175s > > user 0m0.224s > > sys 0m0.020s > > > > > > > > And this is for the PHP version: > > > > Total fetch time: 18 seconds. > > Total fetch bytes: 224888 > > > > real 0m18.077s > > user 0m0.048s > > sys 0m0.028s > > > > Look at the difference in the amount of data transferred. Net::HTTP is > > pulling in *eight times* as much data as curl is. Why is this the case? > > That might be worth more investigation... > > > > But also look at the differences shown; the algorithms themselves take > > nearly no time, which is to be expected. > > > > At any rate (haha, p.i.), you definitely can not make the case that ruby > > is slower than php from this, as all the time is spent in transfer, not > > execution. > > > > P.S. "Mick": I had to clean up your PHP script a bit as it was tossing > > warnings and notices all over. Your ruby script, OTOH, was flawless. I > > did change a couple things in order to get the totals, but not the > > fundamental algorithms. > > Thanks for your answer! > > I think the PHP warnings are because I have disabled them, but think it > would be a good practice to turn them on again haha. > > As you could have seen, in my PHP script, the cURL handle is not closed, > what improves a lot the request speed as I have tested. May be because > of this the Ruby script is slower. The curl handle *is* closed -- it is a local variable (no globals given). Plus, you are in fact reinitializing it every time at the top of the two function calls. //This functions returns body of $url function getBody($url){ $ch = curl_init(); //This functions returns response size function getResponseSize($url){ $ch = curl_init(); (These are from your pastbin entries.) I'd be curious to see what you had when you thought you weren't actually re-initializing, but that's way off topic for this group. > So the "slowness" of the script is because of how connections are > handled I guess. I'm still going with compression vs. non-compressed.