tspace-mysql
Version:
Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.
50 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const perf_hooks_1 = require("perf_hooks");
const lib_1 = require("../lib");
const pattern = 'camelCase';
class User extends lib_1.Model {
constructor() {
super();
this.usePattern(pattern);
this.useUUID();
this.useTimestamp();
this.useSoftDelete();
this.hasMany({ model: Post, name: 'posts' });
this.hasOne({ model: Post, name: 'post' });
}
}
class Post extends lib_1.Model {
constructor() {
super();
this.usePattern(pattern);
this.useUUID();
this.useTimestamp();
this.useSoftDelete();
this.belongsTo({ name: 'user', model: User });
}
}
async function benchmark(func, ...args) {
const start = perf_hooks_1.performance.now();
await func(...args);
const end = perf_hooks_1.performance.now();
return end - start;
}
async function averageBenchmark(func, runs, ...args) {
const benchmarks = [];
for (let i = 0; i < runs; i++) {
benchmarks.push(() => benchmark(func, ...args));
}
const results = await Promise.all(benchmarks.map(v => v()));
const total = results.reduce((acc, time) => acc + time, 0);
return total / runs;
}
async function run() {
const results = await new User().with('posts').limit(10_000).get();
return results;
}
(async () => {
const avgTime = await averageBenchmark(run, 10);
console.log(`Average execution time : ${avgTime.toFixed(0)} ms`);
})();
//# sourceMappingURL=benchmark.test.js.map