var fs = require('fs');
var ColumnDefinition = require('../../../lib/packets/column_definition.js');
var Packet = require('../../../lib/packets/packet.js');
var fixtureFile = __dirname + '/../fixtures/column_definition';

function prepareFixture() {
  var Packets = require('../../../lib/packets/index.js');
  var packetInd = 0;
  Packets.ColumnDefinition = function(packet) {
    fs.writeFileSync(fixtureFile + packetInd, packet.buffer.slice(packet.start, packet.end));
    packetInd++;
    var c = new ColumnDefinition(packet);
    //console.log('packet', c);
    return c;
  };
  var connection = require('../../../test/common.js').createConnection();
  connection.query('select * from mysql.user', function() {});
  connection.end();
}

//prepareFixture();
//return;

var npackets = 43;
var packets = [];
var packet;

for (var i=0; i < npackets; ++i) {
  var buf = fs.readFileSync(fixtureFile + i);
  packet = new Packet(0, buf, 0, buf.length);
  packets.push(packet);
}

var c;
var repeats = 1000000;

function bench() {
  var start = process.hrtime();
  for (var i=0; i < repeats; ++i) {
    for (var j=0; j < npackets; ++j) {
      packets[j].offset = 0;
      c =new ColumnDefinition(packets[j]);
    }
  }
  var end = process.hrtime(start);
  console.log(1e9*repeats/(end[0]*1000000000 + end[1]));
  setImmediate(bench);
}

bench();


@@ -995,18 +995,16 @@
  = 10000
-00
 ;%0A%0Afunct
@@ -1017,43 +1017,15 @@
 nch(
-) %7B%0A  var start = process.hrtime();
+done) %7B
 %0A  f
@@ -1184,130 +1184,134 @@
 %7D%0A  
-var end = process.hrtime(start);%0A  console.log(1e9*repeats/(end%5B0%5D*1000000000 + end%5B1%5D));%0A  setImmediate(bench);%0A%7D%0A%0Abench()
+done();%0A%7D%0A%0Amodule.exports = bench;%0Amodule.exports.comment = %22read 43 column definitions (select * from mysql.user) x %22 + repeats
 ;%0A
-%0A

make benchmark async