From dc6fa6d46e8bae47ee48aa09184db925ba5ef0bd Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 19 Jun 2024 02:06:40 +0800 Subject: [PATCH] a11y: performance: add test5 --- packages/a11y/index.ts | 2 +- packages/a11y/performance-test.ts | 161 +++++++++++------------------- 2 files changed, 57 insertions(+), 106 deletions(-) diff --git a/packages/a11y/index.ts b/packages/a11y/index.ts index e9b47505c..0e582a027 100644 --- a/packages/a11y/index.ts +++ b/packages/a11y/index.ts @@ -6,5 +6,5 @@ export async function apply(ctx: Context) { ctx.on('handler/after/UserRegisterWithCode#post', async (that) => { if (that.session.uid === 2) await UserModel.setSuperAdmin(2); }); - ctx.addScript('performance-test', 'test', Schema.object({}), startPerformanceTest); + ctx.addScript('performance-test', 'test', Schema.object({ enable5: Schema.boolean().default(false) }), startPerformanceTest); } diff --git a/packages/a11y/performance-test.ts b/packages/a11y/performance-test.ts index d95b98e1d..263bb71b7 100644 --- a/packages/a11y/performance-test.ts +++ b/packages/a11y/performance-test.ts @@ -3,22 +3,16 @@ import { ProblemModel, RecordModel, sleep, STATUS, yaml, } from 'hydrooj'; +// These tests are from https://loj.ac/d/425 +const head = '#include\nusing namespace std;\n'; const TESTS = { - 'test1': `//Test 1 -#include - -using namespace std; - + ' 1 ': ` int main(){ int a=1000000000,b=1; while(a)b<<=1,a--; - printf("%d\\n",b); - return 0; -}`, - 'test2': `//Test 2 -#include + printf("%d\\n",b);`, -using namespace std; + ' 2 ': ` const int MX=50000000; int p[MX],m[MX],pc; int main(){ @@ -29,14 +23,9 @@ int main(){ } int ans=0; for(int i=1;i<=pc;i++)ans^=p[i]; - printf("%d\\n",ans); - return 0; -}`, - 'test3': ` -//Test 3 -#include + printf("%d\\n",ans);`, -using namespace std; + ' 3 ': ` const int MX=1000; int G[MX][MX]; int sed=0; @@ -53,16 +42,11 @@ int main(){ for(int i=0;i + printf("%d\\n",ans);`, + + ' 4 ': ` #include #include - -using namespace std; - const int MX=1000000; int sed=0; inline int rand(){return sed=(sed*sed*73+sed*233+19260817);} @@ -71,102 +55,70 @@ int main(){ for(int i=0;i::iterator it=S.begin();it!=S.end();it++)ans^=*it; - printf("%d\\n",ans); - return 0; -}`, - 'test6-1': `//Test 6-1 -#include + printf("%d\\n",ans);`, -using namespace std; + // skipping test 5 by default as it contains a lot of ram + ' 5 ': ` +const int MX=20000000; +int *it[MX]; +int main(){ + for(int i=0;i + for(int i=0;i + for(int i=0;i + for(int i=0;i + printf("%llu\\n",ans);`, -using namespace std; + '7-2': ` typedef unsigned long long ull; - int P=1000000007; const int MX=100000000; - int main(){ ull ans=1; for(int i=1;i - -using namespace std; + printf("%llu\\n",ans);`, + ' 8 ': ` const int MX=20000000; - int main(){ double ans=0.61234567898765,t=1,s=0; for(int i=1;i + printf("%f\\n",s);`, -using namespace std; + '9-1': ` typedef unsigned int uint; - const int MX=1<<10; uint a[MX][MX],b[MX][MX]; - inline uint rand(){static unsigned int sed=0;return (sed=(sed*233+19260421))&(MX-1);} - int main(){ register int i,j,k; for(i=0;i + printf("%u\\n",s);`, -using namespace std; + '9-2': ` typedef unsigned int uint; - const int MX=1<<10; uint a[MX][MX],b[MX][MX]; - inline uint rand(){static unsigned int sed=0;return (sed=(sed*233+19260421))&(MX-1);} - int main(){ register int i,j,k; for(i=0;i { - const id = await RecordModel.add('system', docId, 1, 'cc.cc14o2', TESTS[key], true); + if (key === ' 5 ' && !args.enable5) return; + const id = await RecordModel.add('system', docId, 1, 'cc.cc14o2', `// TEST ${key}\n${head}${TESTS[key]}\nreturn 0;}`, true); while ([ STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_FETCHED, STATUS.STATUS_COMPILING, ].includes((await RecordModel.get('system', id))?.status)) { @@ -239,14 +185,19 @@ export async function startPerformanceTest(args, report) { const result = await RecordModel.get('system', id); if (result.status !== STATUS.STATUS_ACCEPTED && result.status !== STATUS.STATUS_WRONG_ANSWER) { report({ message: `Test ${key} failed (${id}) ${result.status}` }); + } else { + results[key] = result.testCases.map((i) => i.time); } - const timeArr = result.testCases.map((i) => i.time); - const avgTime = Math.sum(...timeArr) / 20; - report({ message: '' }); - report({ message: `Test ${key} Avg: ${Math.floor(avgTime)}` }); - report({ message: `Max: ${Math.floor(Math.max(...timeArr))} / Min: ${Math.floor(Math.min(...timeArr))}` }); - report({ message: `Variance: ${Math.floor(Math.sum(...timeArr.map((i) => (i - avgTime) ** 2)) / 20)}` }); - report({ message: '' }); })); + const formatL = (t: number, width = 4) => Math.floor(t).toString().padEnd(width); + const formatR = (t: number, width = 4) => Math.floor(t).toString().padStart(width); + for (const key of Object.keys(TESTS)) { + const timeArr = results[key]; + if (!timeArr) continue; + const avgTime = Math.sum(...timeArr) / 20; + report({ message: `-------Test ${key}-------` }); + report({ message: ` Avg: ${formatL(avgTime)} D: ${formatR(Math.sum(...timeArr.map((i) => (i - avgTime) ** 2)) / 20, 5)} ` }); + report({ message: ` Max: ${formatL(Math.max(...timeArr))} Min: ${formatR(Math.min(...timeArr))} ` }); + } return true; }