Perl Beats Python in Fetching HTML Pages?
I have a Perl script which is fetching html pages. I tried rewriting it in Python (Just Coz I am trying to learn Python) and I found it to be really slow!

Here's the test Script in Perl

    #!/usr/bin/perl
    use LWP::Simple;

    $url = "http://majorgeeks.com/page.php?id=";

    open(WEB,">>"."perldata.txt");

    for ($column = 1 ; $column <= 20 ; $column ++)

    {

        $temp = $url.$column;
        print "val = $temp\n\n";

        $response=get($temp)or die("[-] Failed!!\n");

        print WEB "$response\n\n";


    }


And here's the Equivalent Code in Python

    import urllib2

    url = "http://majorgeeks.com/page.php?id="

    f = open("pydata.txt", 'w')

    for i in range(20):

       tempurl = url + str(i+1)
       print "Val : " + tempurl + "\n\n"


       req = urllib2.Request(url)
       res = urllib2.urlopen(req)

       f.write(res.read())
    

    f.close()



The difference I found is huge!
Perl Script finished in approx 30 seconds.
While Python Script took 7mins approx. (420 seconds)!!

I am using Ubuntu 11.10, 64bit, Core i7, Tested it on a 12MBPS connection. I tried this several times, and every time I get the same amount of difference.

Am I doing something wrong here? Or I need to do something? Or the difference is justified? (I hope not)

Thanks a lot for your help.

Perl Beats Python in Fetching HTML Pages?
===

I have a Perl script which is fetching html pages. I tried rewriting it in Python (Just Coz I am trying to learn Python) and I found it to be really slow!

Here's the test Script in Perl

    #!/usr/bin/perl
    use LWP::Simple;

    $url = "http://majorgeeks.com/page.php?id=";

    open(WEB,">>"."perldata.txt");

    for ($column = 1 ; $column <= 20 ; $column ++)

    {

        $temp = $url.$column;
        print "val = $temp\n\n";

        $response=get($temp)or die("[-] Failed!!\n");

        print WEB "$response\n\n";


    }


And here's the Equivalent Code in Python

    import urllib2

    url = "http://majorgeeks.com/page.php?id="

    f = open("pydata.txt", 'w')

    for i in range(20):

       tempurl = url + str(i+1)
       print "Val : " + tempurl + "\n\n"


       req = urllib2.Request(url)
       res = urllib2.urlopen(req)

       f.write(res.read())
    

    f.close()



The difference I found is huge!
Perl Script finished in approx 30 seconds.
While Python Script took 7mins approx. (420 seconds)!!

I am using Ubuntu 11.10, 64bit, Core i7, Tested it on a 12MBPS connection. I tried this several times, and every time I get the same amount of difference.

Am I doing something wrong here? Or I need to do something? Or the difference is justified? (I hope not)

Thanks a lot for your help.
