-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
281 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { Database } from './lib/database.ts'; | ||
export * as Operators from './lib/operators.ts'; | ||
export * as Types from './lib/types.ts'; | ||
export * from './lib/helpers.ts'; | ||
export * from './lib/types.ts'; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Database } from '../../mod.ts'; | ||
import { RunBenchmark } from './utils.ts'; | ||
|
||
// Path to the temp file | ||
const TEMP_FILE: string = './temp_benchmark_db.json'; | ||
|
||
// Initialization | ||
const db = new Database({ onlyInMemory: false, immutable: true, path: TEMP_FILE, pretty: true }); | ||
|
||
// Running insertion operations | ||
await RunBenchmark('Insertion', 1000, async (iteration) => { | ||
await db.insertOne({ foo: 'bar' + iteration }); | ||
}); | ||
|
||
// Running searching operations | ||
await RunBenchmark('Searching', 1000, async (iteration) => { | ||
await db.findOne({ foo: 'bar' + iteration }); | ||
}); | ||
|
||
// Running updating operations | ||
await RunBenchmark('Updating', 1000, async (iteration) => { | ||
await db.updateOne({ foo: 'bar' + iteration }, { foo: 'bar' + iteration }); | ||
}); | ||
|
||
// Running deleting operations | ||
await RunBenchmark('Deleting', 1000, async (iteration) => { | ||
await db.deleteMany({ foo: 'bar' + iteration }); | ||
}); | ||
|
||
// Remove temp file | ||
setTimeout(() => { | ||
Deno.removeSync(TEMP_FILE); | ||
}, 1000); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Run benchmark test | ||
* @param name Name of the benchmark | ||
* @param iterations Amount of iterations | ||
* @param test Test to run | ||
*/ | ||
export async function RunBenchmark(name: string, iterations: number, test: (iteration: number) => Promise<void>): Promise<void> { | ||
const testStart = Date.now(); | ||
for(let i = 0; i < iterations; i++) await test(i); | ||
const testEnd = Date.now(); | ||
|
||
const timeResult = testEnd - testStart; | ||
const operationsCount = 1000 / (timeResult / iterations); | ||
const formated = formatNumber(operationsCount); | ||
|
||
console.log(`${name}: ${formated} ops/sec (${timeResult} ms)`); | ||
} | ||
|
||
/** | ||
* Format big numbers to more readable format (16000000 -> 16M) | ||
* @param number Number to format | ||
* @returns Formated number | ||
*/ | ||
export function formatNumber(number: number): string { | ||
if (number >= 1000000) return (number/1000000).toFixed(1) + 'M'; | ||
if (number >= 1000) return (number/1000).toFixed(1) + 'K'; | ||
return number.toFixed(1); | ||
} |
Oops, something went wrong.