title: python 5x slower than perl mySql query
body: <p>I am translating a code from perl to python.
  Even if it works exactly the same, there  is a part of the code that is 5x slower in python than in perl and I cannot figure out why.</p>
  
  <p>Both perl and python are in the same machine, as well as the mysql database.</p>
  
  <p>The code queries a db to download all columns of a table and then process each row.
  There are more than 5 million rows to process and the big issue is in retrieving the data from the database to the python processing.</p>
  
  <p>Here I attach the two code samples: 
  Python:</p>
  
  <pre><code>import os
  import mysql.connector **&lt;--- import mySqlDb**
  import time
  
  outDict = dict()
  ## DB parameters
  db = mysql.connector.connect **&lt;----- mySqlDb.connect( ...** 
       (host=dbhost, 
  user=username, # your username
  passwd=passw, # your password
  db=database) # name of the data base
  cur = db.cursor(prepared=True)
  sql = "select chr,pos,lengthofrepeat,copyNum,region from db.Table_simpleRepeat;"
  cur.execute(sql)
  print('\t eDiVa public omics start')
  s  = time.time()
  sz = 1000
  rows = cur.fetchall()
  for row in rows:
      ## process out dict    
  print time.time() - s 
  cur.close()
  db.close()        
  </code></pre>
  
  <p>While here comes the Perl equivalent script:</p>
  
  <pre><code>use strict;
  use Digest::MD5 qw(md5);
  use DBI;
  use threads;
  use threads::shared;
  
  my $dbh = DBI-&gt;connect('dbi:mysql:'.$database.';host='.$dbhost.'',$username,$pass) 
      or die "Connection Error!!\n";    
      my $sql = "select chr,pos,lengthofrepeat,copyNum,region from   db.Table_simpleRepeat\;";
      ## prepare statement and query
      my $stmt = $dbh-&gt;prepare($sql);
      $stmt-&gt;execute or die "SQL Error!!\n";
      my $c = 0;
      #process query result
      while (my @res = $stmt-&gt;fetchrow_array) 
      {
          $edivaStr{ $res[0].";".$res[1] } = $res[4].",".$res[2]; 
          $c +=1;
      }
      print($c."\n");
      ## close DB connection
      $dbh-&gt;disconnect();    
  </code></pre>
  
  <p>The runtime for these two scripts is:</p>
  
  <ul>
  <li>~40s for the Perl script</li>
  <li>~200s for the Python script</li>
  </ul>
  
  <p>I cannot figure out why this happens [I tried using fetchone() or fetchmany() to see if there are memory issues but the runtime at most reduces 10% from the 200s].</p>
  
  <p>My main problem is understanding why there is such a relevant performance difference between the two functionally equivalent code blocks.</p>
  
  <p>Any idea about how can I verify what is happening would be greatly appreciated.</p>
  
  <p>Thanks!</p>
  
  <h2>UPDATE ABOUT SOLUTION</h2>
  
  <p>Peeyush'comment could be an answer and I'd like him to post it because it allowed me to find a solution.</p>
  
  <p>The problem is the python connector. I just changed that for mySqlDb module which is a C compiled module. That made the python code slightly faster than the perl code.</p>
  
  <p>I added the changes in the python code with a &lt;---- "" to show how easy it has been to gain performance.</p>