mirror of
https://github.com/hanzoai/better-sqlite3.git
synced 2026-09-24 16:57:15 +00:00
updated benchmark
This commit is contained in:
+9
-19
@@ -2,35 +2,25 @@
|
||||
'use strict';
|
||||
const benchmark = require('nodemark');
|
||||
|
||||
const sync = (fn, multiplier) => {
|
||||
const wrapped = () => {
|
||||
for (let i = 0; i < multiplier; ++i) fn();
|
||||
};
|
||||
display(multiplier)(benchmark(wrapped));
|
||||
const sync = (fn) => {
|
||||
display(benchmark(fn));
|
||||
};
|
||||
|
||||
const async = (fn, multiplier) => {
|
||||
const wrapped = (callback) => {
|
||||
const promises = [];
|
||||
for (let i = 0; i < multiplier; ++i) promises.push(fn());
|
||||
Promise.all(promises).then(() => callback(), callback);
|
||||
};
|
||||
benchmark(wrapped).then(display(multiplier));
|
||||
const async = (fn) => {
|
||||
const wrapped = cb => fn().then(() => cb(), cb);
|
||||
benchmark(wrapped).then(display);
|
||||
};
|
||||
|
||||
const display = (multiplier) => (result) => {
|
||||
const hz = Math.round(1e9 / result.mean * multiplier);
|
||||
const error = Math.round(result.error * 10000) / 100;
|
||||
process.stdout.write(`${String(hz).replace(/\B(?=(?:\d{3})+$)/g, ',')} ops/sec \xb1${error}%`);
|
||||
const display = (result) => {
|
||||
process.stdout.write(String(result).replace(/ \(.*/, ''));
|
||||
process.exit();
|
||||
};
|
||||
|
||||
(async () => {
|
||||
process.on('unhandledRejection', (err) => { throw err; });
|
||||
const concurrency = (process.env.CONCURRENCY >>> 0) || (process.env.UV_THREADPOOL_SIZE >>> 0) || 4;
|
||||
const ctx = JSON.parse(process.argv[2]);
|
||||
const db = await require('./drivers').get(ctx.driver)(ctx.filename, ctx.pragma);
|
||||
const fn = require(`./types/${ctx.type}`)[ctx.driver](db, ctx);
|
||||
if (typeof fn === 'function') setImmediate(sync, fn, concurrency);
|
||||
else setImmediate(async, await fn, concurrency);
|
||||
if (typeof fn === 'function') setImmediate(sync, fn);
|
||||
else setImmediate(async, await fn);
|
||||
})();
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ The fastest and simplest library for SQLite3 in Node.js.
|
||||
| |select 1 row `get()` |select 100 rows `all()` |select 100 rows `iterate()` 1-by-1|insert 1 row `run()`|insert 100 rows in a transaction|
|
||||
|---|---|---|---|---|---|
|
||||
|better-sqlite3|1x|1x|1x|1x|1x|
|
||||
|[sqlite](https://www.npmjs.com/package/sqlite) and [sqlite3](https://www.npmjs.com/package/sqlite3)|8.4x slower|3.7x slower|28.2x slower|3.6x slower|6.0x slower|
|
||||
|[sqlite](https://www.npmjs.com/package/sqlite) and [sqlite3](https://www.npmjs.com/package/sqlite3)|10.4x slower|2.2x slower|18.8x slower|2.8x slower|12.9x slower|
|
||||
|
||||
> You can verify these results by [running the benchmark yourself](./benchmark.md).
|
||||
> *Both [npm/sqlite](https://www.npmjs.com/package/sqlite) and [npm/sqlite3](https://www.npmjs.com/package/sqlite3) have nearly identical performance because they both use the [same engine](https://github.com/mapbox/node-sqlite3).*
|
||||
|
||||
+16
-45
@@ -11,56 +11,27 @@ node benchmark
|
||||
|
||||
# Results
|
||||
|
||||
These results are from 08/29/2017, on a MacBook Pro (Retina, 15-inch, Mid 2014, OSX 10.11.6), using nodejs v6.10.3.
|
||||
These results are from 10/08/2018, on a MacBook Pro (Retina, 15-inch, Mid 2014, OSX 10.11.6), using nodejs v10.11.0. All benchmarks are executed in [WAL mode](./performance.md).
|
||||
|
||||
### Reading rows individually (`.get()`)
|
||||
|
||||
```
|
||||
better-sqlite3 x 154,550 ops/sec ±0.52%
|
||||
node-sqlite3 x 18,484 ops/sec ±1.63%
|
||||
```
|
||||
--- reading rows individually ---
|
||||
better-sqlite3 x 283,745 ops/sec ±0.16%
|
||||
node-sqlite3 x 27,191 ops/sec ±0.39%
|
||||
|
||||
### Reading 100 rows into an array (`.all()`)
|
||||
--- reading 100 rows into an array ---
|
||||
better-sqlite3 x 6,650 ops/sec ±0.25%
|
||||
node-sqlite3 x 2,978 ops/sec ±0.33%
|
||||
|
||||
```
|
||||
better-sqlite3 x 7,719 ops/sec ±0.32%
|
||||
node-sqlite3 x 2,078 ops/sec ±1.91%
|
||||
```
|
||||
--- iterating over 100 rows ---
|
||||
better-sqlite3 x 5,231 ops/sec ±0.28%
|
||||
node-sqlite3 x 278 ops/sec ±0.62%
|
||||
|
||||
### Iterating over 100 rows (`.iterate()`)
|
||||
--- inserting rows individually ---
|
||||
better-sqlite3 x 64,920 ops/sec ±5.86%
|
||||
node-sqlite3 x 23,564 ops/sec ±3.58%
|
||||
|
||||
```
|
||||
better-sqlite3 x 5,387 ops/sec ±1.50%
|
||||
node-sqlite3 x 191 ops/sec ±1.64%
|
||||
```
|
||||
|
||||
### Inserting rows individually (`.run()`)
|
||||
|
||||
```
|
||||
--- normal journal mode ---
|
||||
better-sqlite3 x 2,305 ops/sec ±9.06%
|
||||
node-sqlite3 x 1,770 ops/sec ±10.11%
|
||||
|
||||
--- WAL mode ---
|
||||
better-sqlite3 x 65,569 ops/sec ±3.10%
|
||||
node-sqlite3 x 18,302 ops/sec ±3.50%
|
||||
```
|
||||
|
||||
### Inserting 100 rows in a single transaction
|
||||
|
||||
```
|
||||
better-sqlite3 x 1,296 ops/sec ±7.52%
|
||||
node-sqlite3 x 215 ops/sec ±3.57%
|
||||
```
|
||||
|
||||
### "Real world" benchmark
|
||||
|
||||
```
|
||||
--- normal journal mode ---
|
||||
better-sqlite3 x 4,348 ops/sec ±1.54%
|
||||
node-sqlite3 x 3,141 ops/sec ±11.96%
|
||||
|
||||
--- WAL mode ---
|
||||
better-sqlite3 x 102,749 ops/sec ±2.69%
|
||||
node-sqlite3 x 17,532 ops/sec ±6.14%
|
||||
--- inserting 100 rows in a single transaction ---
|
||||
better-sqlite3 x 4,155 ops/sec ±4.45%
|
||||
node-sqlite3 x 321 ops/sec ±1.4%
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user