Skip to content

Commit

Permalink
Add stub DB for compare.
Browse files Browse the repository at this point in the history
  • Loading branch information
kj415j45 committed Aug 10, 2023
1 parent 690d532 commit f85d1b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 5 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -42,6 +43,7 @@ const databases: {
mongo: new MongoDB(),
redisJson: new RedisJson(),
redisGeohash: new RedisGeohash(),
stub: new StubDatabase(),
};

let data: Array<TestData>;
Expand Down Expand Up @@ -128,7 +130,7 @@ new Promise<void>(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";
}
Expand Down Expand Up @@ -214,9 +216,9 @@ new Promise<void>(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";
}
Expand Down
23 changes: 20 additions & 3 deletions src/StubDatabase.ts
Original file line number Diff line number Diff line change
@@ -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<void> {}
async disconnect(): Promise<void> {}
async cleanup(): Promise<void> {}
async create(data: Array<TestData>): Promise<void> {}
async cleanup(): Promise<void> {
this.#size = 0;
}
async create(data: Array<TestData>): Promise<void> {
this.#size += data.length;
}
async prepare(): Promise<void> {}
async usageReport(): Promise<object> {
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<TestData> {
await this.#simulateQuery();
return {
id: "stub",
lng,
Expand All @@ -28,6 +43,7 @@ export class StubDatabase extends TestDatabase {
lat: number,
maxDistance: number
): Promise<Array<TestData>> {
await this.#simulateQuery();
return [
{
id: "stub",
Expand All @@ -42,6 +58,7 @@ export class StubDatabase extends TestDatabase {
lat: number,
maxDistance: number
): Promise<Array<TestData>> {
await this.#simulateQuery();
return [
{
id: "stub",
Expand Down

0 comments on commit f85d1b7

Please sign in to comment.