|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const Benchmark = require('benchmark'); |
| 4 | +const suite = new Benchmark.Suite; |
| 5 | +const parser = require('../'); |
| 6 | + |
| 7 | +let simpleAst = {}; |
| 8 | +let complexAst = {}; |
| 9 | +const simpleSql = ` |
| 10 | + select a from b where c > 1 group by d order by e desc |
| 11 | +`; |
| 12 | +const complexSql = ` |
| 13 | + SELECT rd.*, ((rd.rd_numberofrooms) - (select sum(rn.reservation_numberofrooms) as count_reserve_room from reservation as rn WHERE rn.reservation_rd_id = rd.rd_id AND (str_to_date('$data_Check_in_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_out_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_in_date','%d-%m-%y') <= str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date('$data_Check_out_date','%d-%m-%y') ) )) as reserve |
| 14 | +
|
| 15 | +FROM room_details rd LEFT JOIN reservation rn ON rd.rd_id = rn.reservation_rd_id WHERE NOT EXISTS |
| 16 | +
|
| 17 | +( |
| 18 | +
|
| 19 | +SELECT rn.* FROM reservation rn WHERE rn.reservation_rd_id = rd.rd_id |
| 20 | +
|
| 21 | +AND (str_to_date('$data_Check_in_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_out_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_in_date','%d-%m-%y') <= str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date('$data_Check_out_date','%d-%m-%y') >= str_to_date(rn.reservation_check_out_date,'%d-%m-%y')) |
| 22 | +
|
| 23 | +AND (rd.rd_numberofrooms <= (select sum(rn.reservation_numberofrooms) as count_reserve_room from reservation as rn WHERE rn.reservation_rd_id = rd.rd_id AND (str_to_date('$data_Check_in_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_out_date','%d-%m-%y') BETWEEN str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date(rn.reservation_check_out_date,'%d-%m-%y') OR str_to_date('$data_Check_in_date','%d-%m-%y') <= str_to_date(rn.reservation_check_in_date,'%d-%m-%y') AND str_to_date('$data_Check_out_date','%d-%m-%y') ) ) ) |
| 24 | +
|
| 25 | +) |
| 26 | +`; |
| 27 | + |
| 28 | +suite |
| 29 | +.add('simpleSql', function () { |
| 30 | + let ast = parser.parse(simpleSql); |
| 31 | + let newSql = parser.stringify(ast); |
| 32 | +}) |
| 33 | +.add('complexSql', function () { |
| 34 | + let ast = parser.parse(complexSql); |
| 35 | + let newSql = parser.stringify(ast); |
| 36 | +}) |
| 37 | +.add('simpleParse', function () { |
| 38 | + simpleAst = parser.parse(simpleSql); |
| 39 | +}) |
| 40 | +.add('complexParse', function () { |
| 41 | + complexAst = parser.parse(complexSql); |
| 42 | +}) |
| 43 | +.add('simpleStringify', function () { |
| 44 | + parser.stringify(simpleAst); |
| 45 | +}) |
| 46 | +.add('complexStringify', function () { |
| 47 | + parser.stringify(complexAst); |
| 48 | +}) |
| 49 | +.on('cycle', function (event) { |
| 50 | + console.log('' + event.target); |
| 51 | +}) |
| 52 | +.run(); |
| 53 | + |
0 commit comments