diff --git a/index.ts b/index.ts index df0653b..9cce4ac 100644 --- a/index.ts +++ b/index.ts @@ -18,6 +18,7 @@ import { import { Command } from "commander"; import { RedisJson } from "./src/Redis/RedisJson"; import { RedisGeohash } from "./src/Redis/RedisGeohash"; +import { StubDatabase } from "./src/StubDatabase"; const program = new Command("geospatial-benchmark"); @@ -42,6 +43,7 @@ const databases: { mongo: new MongoDB(), redisJson: new RedisJson(), redisGeohash: new RedisGeohash(), + stub: new StubDatabase(), }; let data: Array; @@ -128,7 +130,7 @@ new Promise(async (resolve, reject) => { fs.writeFileSync(`./results/${title}.input`, JSON.stringify({ lng, lat })); for (const database of Object.values(databases)) { let data = await database.queryA(lng, lat); - let message = `${database.name()} => ${data}`; + let message = `${database.name()} => ${JSON.stringify(data)}`; console.log(message); output += message + "\n"; } @@ -214,9 +216,9 @@ new Promise(async (resolve, reject) => { ); for (const database of Object.values(databases)) { let data = await database.queryC(lng, lat, distance); - let message = `${database.name()} => ${data.length} => ${ + let message = `${database.name()} => ${data.length} => ${JSON.stringify( data[data.length - 1] - }`; + )}`; console.log(message); output += message + "\n"; } diff --git a/src/StubDatabase.ts b/src/StubDatabase.ts index 0233481..3a969e4 100644 --- a/src/StubDatabase.ts +++ b/src/StubDatabase.ts @@ -1,21 +1,36 @@ import { TestData } from "./TestData"; import { TestDatabase } from "./TestDatabase"; +import { delay } from "./utils"; export class StubDatabase extends TestDatabase { + #size = 0; + name(): string { return "Stub"; } async connect(uri?: string | undefined): Promise {} async disconnect(): Promise {} - async cleanup(): Promise {} - async create(data: Array): Promise {} + async cleanup(): Promise { + this.#size = 0; + } + async create(data: Array): Promise { + this.#size += data.length; + } async prepare(): Promise {} async usageReport(): Promise { - return {}; + return { + msg: "This is a stub database. Query ops should be static 100 ops/sec.", + size: this.#size, + }; + } + + #simulateQuery() { + return delay(0.01); } async queryA(lng: number, lat: number): Promise { + await this.#simulateQuery(); return { id: "stub", lng, @@ -28,6 +43,7 @@ export class StubDatabase extends TestDatabase { lat: number, maxDistance: number ): Promise> { + await this.#simulateQuery(); return [ { id: "stub", @@ -42,6 +58,7 @@ export class StubDatabase extends TestDatabase { lat: number, maxDistance: number ): Promise> { + await this.#simulateQuery(); return [ { id: "stub",