2014-09-01 17:18:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-04-21 19:56:01 -04:00
|
|
|
var Promise = require('bluebird');
|
|
|
|
var fs = Promise.promisifyAll(require('fs'));
|
|
|
|
var shelljs = Promise.promisifyAll(require('shelljs'));
|
|
|
|
var rimraf = Promise.promisify(require('rimraf'));
|
|
|
|
|
|
|
|
var tmpDir = __dirname + '/temp';
|
|
|
|
|
|
|
|
Promise.try(function() {
|
|
|
|
return rimraf(tmpDir).catch(function(){}).finally(function() {
|
|
|
|
return fs.mkdirAsync(tmpDir);
|
|
|
|
});
|
|
|
|
}).then(function() {
|
|
|
|
return shelljs.execAsync('cp -r ' + __dirname + '/../../.git ' + tmpDir);
|
|
|
|
}).then(function() {
|
|
|
|
shelljs.cd(tmpDir);
|
|
|
|
shelljs.exec('git reset --hard');
|
|
|
|
shelljs.exec('git checkout master');
|
|
|
|
shelljs.exec('npm install');
|
|
|
|
}).then(function() {
|
|
|
|
var Benchmark = require('benchmark');
|
|
|
|
var Knex1 = require(tmpDir + '/knex.js');
|
|
|
|
var Knex2 = require('../../knex');
|
2014-09-01 17:18:45 +02:00
|
|
|
var suite = new Benchmark.Suite();
|
|
|
|
var knex1 = Knex1.initialize({client: 'mysql', connection: {}});
|
|
|
|
var knex2 = Knex2.initialize({client: 'mysql'});
|
2014-04-21 19:56:01 -04:00
|
|
|
|
|
|
|
suite
|
|
|
|
.add('0.5.13: simple where clauses', function() {
|
|
|
|
var str = knex1('item').select('name').where('active', true).orWhere('id', 2).orWhere('id', function() {
|
|
|
|
this.select('*').from('users').whereIn('id', [44, 22]);
|
|
|
|
}).toSql();
|
|
|
|
if (!global.logged1) {
|
|
|
|
console.log(str);
|
|
|
|
global.logged1 = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.add('0.6.0-alpha: simple where clauses', function() {
|
|
|
|
var str = knex2('item').select('name').where('active', true).orWhere('id', 2).orWhere('id', function() {
|
|
|
|
this.select('*').from('users').whereIn('id', [44, 22]);
|
|
|
|
}).toSQL();
|
|
|
|
if (!global.logged2) {
|
|
|
|
console.log(str);
|
|
|
|
global.logged2 = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// add listeners
|
2014-09-02 22:56:51 +02:00
|
|
|
.on('error', function() {
|
2014-04-21 19:56:01 -04:00
|
|
|
console.log(arguments);
|
|
|
|
})
|
|
|
|
.on('cycle', function(event) {
|
|
|
|
console.log(String(event.target));
|
|
|
|
})
|
|
|
|
.on('complete', function() {
|
|
|
|
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
|
|
|
|
process.exit(0);
|
|
|
|
})
|
|
|
|
// run async
|
|
|
|
.run({ 'async': true });
|
2014-09-01 17:18:45 +02:00
|
|
|
});
|