-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.js
60 lines (56 loc) · 1.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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');
var suite = new Benchmark.Suite;
global.knex1 = Knex1.initialize({client: 'mysql', connection: {}});
global.knex2 = Knex2.initialize({client: 'mysql'});
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
.on('error', function(event) {
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 });
});