Skip to content

Commit

Permalink
made benchmarks more transparent and realistic
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Apr 12, 2017
1 parent 01d58ab commit 1e05dfb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
5 changes: 4 additions & 1 deletion benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ var trials;
}());

function getTrials() {
return process.argv.slice(2).reduce(filterByArgs, require('./trials').map(addSearchTerms));
var trials = require('./trials');
var specifiedGroup = trials.hasOwnProperty(process.argv[2]) ? process.argv[2] : '';
var args = process.argv.slice(specifiedGroup ? 3 : 2);
return args.reduce(filterByArgs, trials[specifiedGroup || 'default'].map(addSearchTerms));

function addSearchTerms(trial) {
var size = trial.table.toLowerCase().indexOf('large') === -1 ? 'small' : 'large';
Expand Down
31 changes: 19 additions & 12 deletions benchmark/trials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = [
exports.default = [
{type: 'select', table: 'allSmall', columns: ['integer']},
{type: 'select', table: 'allSmall', columns: ['real']},
{type: 'select', table: 'allSmall', columns: ['text']},
Expand Down Expand Up @@ -42,17 +42,24 @@ module.exports = [
{type: 'transaction', table: 'blobSmall', columns: ['blob']},
{type: 'transaction', table: 'nulSmall', columns: ['nul']},
{type: 'transaction', table: 'textLarge', columns: ['text']},
{type: 'transaction', table: 'blobLarge', columns: ['blob']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'blob', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'blob', 'nul'], pragma: ['journal_mode = DELETE']}
{type: 'transaction', table: 'blobLarge', columns: ['blob']}
];

if (/^(1|true|on|yes)$/i.test(process.env.NO_CACHE)) {
module.exports.forEach(function (trial) {
trial.pragma = ['cache_size = 0'].concat(trial.pragma || []);
});
} else {
module.exports.forEach(function (trial) {
trial.pragma = ['cache_size = -16000'].concat(trial.pragma || []);
exports.rows = [
{type: 'select', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'select-all', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'select-each', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'insert', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'insert', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = DELETE']},
{type: 'transaction', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = DELETE']}
];

(function () {
var cacheSize = /^(1|true|on|yes)$/i.test(process.env.NO_CACHE) ? 'cache_size = 0' : 'cache_size = -16000';
var trials = [].concat.apply([], Object.keys(exports).map(function (key) {return exports[key];}));
trials.forEach(function (trial) {
trial.pragma = [cacheSize].concat(trial.pragma || []);
});
}
}());
7 changes: 2 additions & 5 deletions benchmark/types/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ require('../runner')(function (benchmark, dbs, ctx) {
var nodeSqlite3 = dbs['node-sqlite3'];
var data = factory(ctx.table, ctx.columns);

var stmt = betterSqlite3.prepare(SQL);
var betterSqlite3Insert = betterSqlite3.prepare(SQL);

benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).run(data);
});
benchmark.add(' + optimized', function () {
stmt.run(data);
betterSqlite3Insert.run(data);
});
benchmark.add('node-sqlite3', function (deferred) {
nodeSqlite3.run(SQL, data).then(function () {deferred.resolve();});
Expand Down
8 changes: 2 additions & 6 deletions benchmark/types/select-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ require('../runner')(function (benchmark, dbs, ctx) {
var rowid = 99;
benchmark.on('cycle', function () {rowid = 0;});

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);

benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).all(rowid % 1000 - 98);
rowid += 100;
});
benchmark.add(' + optimized', function () {
stmt.all(rowid % 1000 - 98);
betterSqlite3Select.all(rowid % 1000 - 98);
rowid += 100;
});
benchmark.add('node-sqlite3', function (deferred) {
Expand Down
8 changes: 2 additions & 6 deletions benchmark/types/select-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ require('../runner')(function (benchmark, dbs, ctx) {
var rowid = 99;
benchmark.on('cycle', function () {rowid = 0;});

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);

benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).each(rowid % 1000 - 98, function () {});
rowid += 100;
});
benchmark.add(' + optimized', function () {
stmt.each(rowid % 1000 - 98, function () {});
betterSqlite3Select.each(rowid % 1000 - 98, function () {});
rowid += 100;
});
benchmark.add('node-sqlite3', function (deferred) {
Expand Down
7 changes: 2 additions & 5 deletions benchmark/types/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ require('../runner')(function (benchmark, dbs, ctx) {
var rowid = 0;
benchmark.on('cycle', function () {rowid = 0;});

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);

benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).get(rowid++ % 1000 + 1);
});
benchmark.add(' + optimized', function () {
stmt.get(rowid++ % 1000 + 1);
betterSqlite3Select.get(rowid++ % 1000 + 1);
});
benchmark.add('node-sqlite3', function (deferred) {
nodeSqlite3.get(SQL, rowid++ % 1000 + 1).then(function () {deferred.resolve();});
Expand Down
7 changes: 2 additions & 5 deletions benchmark/types/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ require('../runner')(function (benchmark, dbs, ctx) {
var data = namedData(ctx.table, ctx.columns);
var dataWithPrefix = namedData(ctx.table, ctx.columns, true);

var transaction = betterSqlite3.transaction(new Array(100).fill(SQL));
var betterSqlite3Transaction = betterSqlite3.transaction(new Array(100).fill(SQL));

benchmark.add('better-sqlite3', function () {
betterSqlite3.transaction(new Array(100).fill(SQL)).run(data);
});
benchmark.add(' + optimized', function () {
transaction.run(data);
betterSqlite3Transaction.run(data);
});
benchmark.add('node-sqlite3', function (deferred) {
var count = 0;
Expand Down

0 comments on commit 1e05dfb

Please sign in to comment.