From 93c5741b5d31bc0d3b30451929c9cd587eac35fb Mon Sep 17 00:00:00 2001 From: jer-echo Date: Thu, 23 Jun 2022 09:42:23 +0800 Subject: [PATCH] added test for deno --- test.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/test.ts b/test.ts index e9366ac..b550762 100644 --- a/test.ts +++ b/test.ts @@ -1,20 +1,55 @@ +// Deno compatible only import Numesis from './mod.ts' -const n = new Numesis(); -const countStart = 999999999 -const countEnd = 1000001999 +async function test(s: number): Promise<{ + id: string[], + start: number, + end: number, +}> { + const n = new Numesis(); + return new Promise((resolve) => { + let ts = Date.now() + let te = Date.now() + let de: string[] = [] + var stop = false -let ts = Date.now() -let de: string[] = [] -let dp: string[] = [] + for (let i = 0; !stop; i++) { + de.push(n.e(i)) + te = Date.now() + if (te - ts >= s * 1000) { + stop = true; + return resolve({ start: ts, end: te, id: de }) + } + } + }) +} -for(let i = countStart;i < countEnd;i++){ - const e = n.e(i) - if(de.includes(e)) dp.push(e) - de.push(e) +async function average(s: number) { + const id: number[] = [] + const dup: number[] = [] + for (let i = 0; i < s; i++) { + await test(1) + .then(({ id: e }) => { + id.push(e.length) + dup.push(e.length - (new Set(e)).size) + }) + } + const avg = id.reduce((a, b) => a + b, 0) / id.length + const avgDup = dup.reduce((a, b) => a + b, 0) / dup.length + console.log(`\n=====================================================`) + console.log("Average ID's:", ~~avg, "/s") + console.log(`Average duplicated ID's: ${~~avgDup}/s`) + console.log(`Elapsed time: ${s}s`) } -let te = Date.now() -console.log(`\n===========================================`) -console.log("Generated ID's \t\t\t:",de.length) -console.log("Duplicated ID's \t\t:",dp.length) // should be 0 to pass -console.log("Elapsed time \t\t\t:", (te - ts)/1000,"s") \ No newline at end of file + +test(1) + .then((e) => { + console.log(`\n=====================================================`) + console.log("Average Generated ID's \t\t\t:", e?.id?.length) + console.log("Average Duplicated ID's \t\t:", e?.id?.length - (new Set(e?.id)).size) + console.log("Elapsed time \t\t\t\t:", (e?.end - e?.start) / 1000, "s") + return 0; + }) + +average(10) +