Skip to content

Commit

Permalink
chore: apply modern code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSchick committed Nov 21, 2018
1 parent 33b94d3 commit b38c3a4
Show file tree
Hide file tree
Showing 84 changed files with 465 additions and 714 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
"node": true
},
"rules": {
"template-curly-spacing": ["error", "never"],
"prefer-template": "error",
"no-useless-call": "error",
"no-lonely-if": "error",
"indent": ["error", 2, {
"SwitchCase": 1
}],
"no-else-return": ["error", {
"allowElseIf": false
}],
"eqeqeq": "error",
"no-invalid-this": "error",
"consistent-this": "error",
"prefer-arrow-callback": "error",
Expand Down
16 changes: 0 additions & 16 deletions .npmignore

This file was deleted.

21 changes: 9 additions & 12 deletions benchmarks/FB/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (cluster.isMaster) {
}

cluster.on('exit', worker => {
console.log('worker ' + worker.pid + ' died');
console.log(`worker ${worker.pid} died`);
});

return;
Expand Down Expand Up @@ -73,7 +73,7 @@ function handlePrepared(req, res) {
[getRandomNumber()],
(err, rows) => {
results.push(rows[0]);
if (results.length == queries) res.end(JSON.stringify(results));
if (results.length === queries) res.end(JSON.stringify(results));
}
);
}
Expand All @@ -91,7 +91,7 @@ function handleMysqlIsh(conn, req, res) {
[getRandomNumber()],
(err, rows) => {
results.push(rows[0]);
if (results.length == queries) res.end(JSON.stringify(results));
if (results.length === queries) res.end(JSON.stringify(results));
}
);
}
Expand All @@ -105,10 +105,10 @@ function handleMysqlIshPool(pool, req, res) {
for (let i = 0; i < queries; ++i) {
pool.getConnection(() => {
mysql2conn.query(
'SELECT * FROM world WHERE id = ' + getRandomNumber(),
`SELECT * FROM world WHERE id = ${getRandomNumber()}`,
(err, rows) => {
results.push(rows[0]);
if (results.length == queries) res.end(JSON.stringify(results));
if (results.length === queries) res.end(JSON.stringify(results));
}
);
});
Expand All @@ -125,7 +125,7 @@ function handleMaria(req, res) {
.on('result', dbres => {
dbres.on('row', row => {
results.push(row);
if (results.length == queries) res.end(JSON.stringify(results));
if (results.length === queries) res.end(JSON.stringify(results));
});
});
}
Expand Down Expand Up @@ -207,7 +207,7 @@ http

function libmysqlQuery2(callback) {
libmysql.query(
'SELECT * FROM world WHERE id = ' + getRandomNumber(),
`SELECT * FROM world WHERE id = ${getRandomNumber()}`,
(err, res) => {
if (err) {
throw err;
Expand Down Expand Up @@ -278,7 +278,7 @@ http

function libmysqlQuery(callback) {
libmysql.query(
'SELECT * FROM world WHERE id = ' + getRandomNumber(),
`SELECT * FROM world WHERE id = ${getRandomNumber()}`,
(err, res) => {
if (err) {
throw err;
Expand All @@ -293,10 +293,7 @@ http

rows[0].randomNumber = getRandomNumber();
libmysql.query(
'UPDATE World SET randomNumber = ' +
rows[0].randomNumber +
' WHERE id = ' +
rows[0]['id'],
`UPDATE World SET randomNumber = ${rows[0].randomNumber} WHERE id = ${rows[0]['id']}`,
err => {
if (err) {
throw err;
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/bench-fake-server-maria.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ function benchmarkSelects(n, cb) {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log(
' rows: ' +
(numSelects * 1e9) / diff +
' results/sec, ' +
(rowsPerQuery * numSelects * 1e9) / diff +
' rows/sec'
` rows: ${(numSelects * 1e9) / diff} results/sec, ${(rowsPerQuery * numSelects * 1e9) / diff} rows/sec`
);
if (n > 1) benchmarkSelects(n - 1, cb);
else cb();
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/bench-fake-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for (let i = 0; i < connections.length; ++i)
let currConn = 0;
function next() {
currConn++;
if (currConn == connections.length) currConn = 0;
if (currConn === connections.length) currConn = 0;
connection = connections[currConn];
}
// ======================
Expand Down Expand Up @@ -39,11 +39,7 @@ function benchmarkSelects(n, cb) {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log(
' rows: ' +
(numSelects * 1e9) / diff +
' results/sec, ' +
(rowsPerQuery * numSelects * 1e9) / diff +
' rows/sec'
` rows: ${(numSelects * 1e9) / diff}} results/sec, ${(rowsPerQuery * numSelects * 1e9) / diff} rows/sec`
);
if (n > 1) benchmarkSelects(n - 1, cb);
else cb();
Expand Down
17 changes: 6 additions & 11 deletions benchmarks/bench-insert-select-parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const connection = common.createConnection();
const table = 'insert_test';
//const text = "本日は晴天なり";
const text = 'test abc xyz';
connection.query('drop table ' + table).on('error', () => {});
connection.query(`drop table ${table}`).on('error', () => {});
connection.query(
[
'CREATE TABLE `' + table + '` (',
`CREATE TABLE \`${table}\` (`,
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255) NOT NULL,',
'PRIMARY KEY (`id`)',
Expand All @@ -19,7 +19,7 @@ connection.query(

function benchmarkInsert(numLeft, callback) {
connection.query(
'INSERT INTO ' + table + ' SET title="' + text + '"',
`INSERT INTO ${table} SET title="${text}"`,
err => {
if (err) throw err;
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
Expand All @@ -34,7 +34,7 @@ function benchmarkInserts(n, cb) {
benchmarkInsert(numInsert, () => {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log((numInsert * 1e9) / diff + ' inserts/sec');
console.log(`${(numInsert * 1e9) / diff} inserts/sec`);
if (n > 1) benchmarkInserts(n - 1, cb);
else cb();
});
Expand All @@ -51,12 +51,7 @@ function benchmarkParallelSelects(n, size, cb) {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log(
size +
' rows: ' +
(n * 1e9) / diff +
' results/sec, ' +
(size * n * 1e9) / diff +
' rows/sec'
`${size} rows: ${(n * 1e9) / diff} results/sec, ${(size * n * 1e9) / diff} rows/sec`
);
cb();
}
Expand All @@ -66,7 +61,7 @@ function benchmarkParallelSelects(n, size, cb) {
numRunning++;
connections[i] = common.createConnection();
const cmd = connections[i].execute(
'select * from ' + table + ' limit ' + size,
`select * from ${table} limit ${size}`,
[]
);
cmd.on('end', commandDone);
Expand Down
15 changes: 5 additions & 10 deletions benchmarks/bench-insert-select-prepared.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const table = 'insert_test';
const text = 'test abc xyz';
connection.query(
[
'CREATE TEMPORARY TABLE `' + table + '` (',
`CREATE TEMPORARY TABLE \`${table}\` (`,
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255),',
'PRIMARY KEY (`id`)',
Expand All @@ -18,7 +18,7 @@ connection.query(

function benchmarkInsert(numLeft, callback) {
connection.execute(
'INSERT INTO ' + table + ' SET title="' + text + '"',
`INSERT INTO ${table} SET title="${text}"`,
[],
err => {
if (err) throw err;
Expand All @@ -34,15 +34,15 @@ function benchmarkInserts(n, cb) {
benchmarkInsert(numInsert, () => {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log((numInsert * 1e9) / diff + ' inserts/sec');
console.log(`${(numInsert * 1e9) / diff} inserts/sec`);
if (n > 1) benchmarkInserts(n - 1, cb);
else cb();
});
}

function benchmarkSelect(numLeft, numSelect, callback) {
connection.execute(
'select * from ' + table + ' limit ' + numSelect,
`select * from ${table} limit ${numSelect}`,
[],
err => {
if (err) throw err;
Expand All @@ -59,12 +59,7 @@ function benchmarkSelects(n, size, cb) {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log(
size +
' rows: ' +
(numSelects * 1e9) / diff +
' results/sec, ' +
(size * numSelects * 1e9) / diff +
' rows/sec'
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size * numSelects * 1e9) / diff} rows/sec`
);
if (n > 1) benchmarkSelects(n - 1, size, cb);
else cb();
Expand Down
15 changes: 5 additions & 10 deletions benchmarks/bench-insert-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const table = 'insert_test';
const text = '本日は晴天なり';
connection.query(
[
'CREATE TEMPORARY TABLE `' + table + '` (',
`CREATE TEMPORARY TABLE \`${table}\` (`,
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`title` varchar(255),',
'PRIMARY KEY (`id`)',
Expand All @@ -17,7 +17,7 @@ connection.query(

function benchmarkInsert(numLeft, callback) {
connection.query(
'INSERT INTO ' + table + ' SET title="' + text + '"',
`INSERT INTO ${table} SET title="${text}"`,
err => {
if (err) throw err;
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
Expand All @@ -32,14 +32,14 @@ function benchmarkInserts(n, cb) {
benchmarkInsert(numInsert, () => {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log((numInsert * 1e9) / diff + ' inserts/sec');
console.log(`${(numInsert * 1e9) / diff} inserts/sec`);
if (n > 1) benchmarkInserts(n - 1, cb);
else cb();
});
}

function benchmarkSelect(numLeft, numSelect, callback) {
connection.query('select * from ' + table + ' limit ' + numSelect, err => {
connection.query(`select * from ${table} limit ${numSelect}`, err => {
if (err) throw err;
if (numLeft > 1) benchmarkSelect(numLeft - 1, numSelect, callback);
else callback();
Expand All @@ -53,12 +53,7 @@ function benchmarkSelects(n, size, cb) {
const end = process.hrtime();
const diff = common.hrdiff(start, end);
console.log(
size +
' rows: ' +
(numSelects * 1e9) / diff +
' results/sec, ' +
(size * numSelects * 1e9) / diff +
' rows/sec'
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size * numSelects * 1e9) / diff} rows/sec`
);
if (n > 1) benchmarkSelects(n - 1, size, cb);
else cb();
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmark-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const sql = process.argv[2];
const curTime = Date.now();
const last1000time = curTime - prev1000;
prev1000 = curTime;
console.error(1000000 / last1000time + ' req/sec');
console.error(`${1000000 / last1000time} req/sec`);
}

if (left > 0) bench();
else {
console.error(
10000000 / (Date.now() - start) + ' req/sec (average 10000 reqs)'
`${10000000 / (Date.now() - start)} req/sec (average 10000 reqs)`
);
db.end();
if (cb) cb();
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/http-select-and-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const port = process.env.PORT;
http
.createServer((req, res) => {
const q = url.parse(req.url, true);
if (q.pathname == '/render') {
if (q.pathname === '/render') {
const sql = q.query.q;
const n = q.query.n;
let rowsTotal = [];
Expand Down
8 changes: 3 additions & 5 deletions benchmarks/ruby-mysql2/benchmark-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ let numRequests = 0;
const curTime = Date.now();
const last1000time = curTime - prev1000;
prev1000 = curTime;
console.error(1000000 / last1000time + ' req/sec');
console.error(`${1000000 / last1000time} req/sec`);
}

if (left > 0) bench();
else {
console.error(
(numRequests * 1000) / (Date.now() - start) +
' req/sec (average 10000 reqs)'
`${(numRequests * 1000) / (Date.now() - start)} req/sec (average 10000 reqs)`
);
console.error(
(rowsReceived * 1000) / (Date.now() - start) +
' row/sec (average 10000 reqs)'
`${(rowsReceived * 1000) / (Date.now() - start)} row/sec (average 10000 reqs)`
);
db.end();
if (cb) cb();
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/run-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function runFolder(name, done) {

function benchmarkModule(m, modulePath, done) {
const results = [];
const bar = new progress(m.comment + ' [:bar] ', {
const bar = new progress(`${m.comment} [:bar] `, {
total: nRepeats,
clear: true
});
Expand Down Expand Up @@ -122,11 +122,11 @@ function runFileList(base, list, done) {
if (index >= list.length) {
return done(null, results);
}
const fname = base + '/' + list[index];
const fname = `${base}/${list[index]}`;
fs.stat(fname, (err, stat) => {
if (err) return done(err);
if (stat.isDirectory()) return runFolder(fname, runOne);
else if (fname.slice(-3) == '.js') {
if (fname.endsWith('.js')) {
const m = require(fname);
return benchmarkModule(m, fname, runOne);
}
Expand All @@ -137,7 +137,7 @@ function runFileList(base, list, done) {
}

//const name = process.argv[2] || __dirname + '/unit';
runFolder(__dirname + '/unit', (err, results) => {
runFolder(`${__dirname}/unit`, (err, results) => {
//console.log(results);
fs.writeFileSync(__dirname + '/results.json', JSON.stringify(results));
fs.writeFileSync(`${__dirname}/results.json`, JSON.stringify(results));
});
Loading

0 comments on commit b38c3a4

Please sign in to comment.