Skip to content

Commit 3c5eebc

Browse files
committed
test: warm up g++ before judging to avoid cold-start penalty
First g++ invocation on CI takes ~45s (cold start). Subsequent invocations take ~300ms. Pre-compile a trivial program in initTestCase() so the judging test only sees the warm-cache timing.
1 parent 85add0e commit 3c5eebc

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/test1/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ class TestContest : public QObject {
159159
}
160160
};
161161
copyDir(m_contestDir, dst, copyDir);
162+
163+
// Warm up g++: compile a trivial program to pay the cold-start cost
164+
// upfront instead of during the timed judging test.
165+
{
166+
QString gppPath = QStandardPaths::findExecutable("g++");
167+
if (!gppPath.isEmpty()) {
168+
QProcess warmup;
169+
warmup.start(gppPath, {"-x", "c++", "-O2", "-o",
170+
m_tempWorkDir.path() + "/_warmup.exe", "-"});
171+
warmup.write("int main(){return 0;}");
172+
warmup.closeWriteChannel();
173+
warmup.waitForFinished(60000);
174+
}
175+
}
162176
}
163177

164178
// ------------------------------------------------------------------

0 commit comments

Comments
 (0)