Skip to content

Commit

Permalink
fix: for breaking ffi api changes & optimize some functions for fasta…
Browse files Browse the repository at this point in the history
…pi (#43)

* work

* revert codegen for now
  • Loading branch information
DjDeveloperr authored Aug 21, 2022
1 parent 30e0ef4 commit 8324685
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 120 deletions.
86 changes: 86 additions & 0 deletions bench/fast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Database } from "../mod.ts";
import { DB } from "https://deno.land/x/[email protected]/mod.ts";
// import { lib } from "../src/ffi.ts";

await Deno.remove("temp.db").catch(() => {});
await Deno.remove("temp2.db").catch(() => {});
const db = new Database("temp.db");
const db2 = new DB("temp2.db");

[
"pragma journal_mode = WAL",
"pragma synchronous = normal",
"pragma temp_store = memory",
"create table test (key integer primary key autoincrement, value text not null)",
].forEach((query) => {
db.execute(query);
db2.execute(query);
});

// const ptr = Number(db.unsafeRawHandle);
// const {} = lib;

Deno.bench("nop", () => {});

Deno.bench("[ffi] query version", () => {
db.queryArray("select sqlite_version()");
});

Deno.bench("[wasm] query version", () => {
db2.queryEntries("select sqlite_version()");
});

Deno.bench("[ffi] insert", () => {
const prep = db.prepare("insert into test (value) values (?)");
for (let i = 0; i < 10; i++) {
prep.execute(`loop ${i}`);
}
prep.finalize();
});

Deno.bench("[wasm] insert", () => {
const prep = db2.prepareQuery("insert into test (value) values (?)");
for (let i = 0; i < 10; i++) {
prep.execute([`loop ${i}`]);
}
prep.finalize();
});

Deno.bench("[ffi] query", () => {
db.queryArray("select * from test");
});

Deno.bench("[wasm] query", () => {
db2.queryEntries("select * from test");
});

Deno.bench("[ffi] db.changes", () => {
const _ = db.changes;
});

Deno.bench("[wasm] db.changes", () => {
const _ = db2.changes;
});

Deno.bench("[ffi] db.totalChanges", () => {
const _ = db.totalChanges;
});

Deno.bench("[wasm] db.totalChanges", () => {
const _ = db2.totalChanges;
});

Deno.bench("[ffi] db.lastInsertRowId", () => {
const _ = db.lastInsertRowId;
});

Deno.bench("[wasm] db.lastInsertRowId", () => {
const _ = db2.lastInsertRowId;
});

window.onunload = () => {
db.close();
db2.close();
Deno.removeSync("temp.db");
Deno.removeSync("temp2.db");
};
2 changes: 2 additions & 0 deletions bench/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const ROWS = 10;

const backends: Backend[] = [native, wasm];

Deno.bench("nop", () => {});

for (const backend of backends) {
backend.execute("pragma journal_mode = WAL", []);
backend.execute("pragma synchronous = normal", []);
Expand Down
2 changes: 1 addition & 1 deletion bench/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DB } from "https://deno.land/x/sqlite@v3.0.0/mod.ts";
import { DB } from "https://deno.land/x/sqlite@v3.4.0/mod.ts";
import { fromFileUrl } from "../deps.ts";
import { Backend } from "./backend.ts";

Expand Down
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { fromFileUrl } from "https://deno.land/std@0.145.0/path/mod.ts";
export { fromFileUrl } from "https://deno.land/std@0.152.0/path/mod.ts";
2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Database {
}

/** Unsafe Raw (pointer) to the sqlite object */
get unsafeRawHandle(): bigint {
get unsafeRawHandle(): Deno.PointerValue {
return this.#handle;
}

Expand Down
Loading

0 comments on commit 8324685

Please sign in to comment.