feat:add prototype timer for program running and compiling
This commit is contained in:
parent
3929c055eb
commit
0eab496c8d
@ -76,9 +76,29 @@ export const runMultiFileCodeWithOptionalTestData = async (params: {
|
|||||||
// 阶段2: 准备编译命令
|
// 阶段2: 准备编译命令
|
||||||
stageStart = performance.now();
|
stageStart = performance.now();
|
||||||
const compileAndRunCmd = {
|
const compileAndRunCmd = {
|
||||||
c: `cd ${dockerConfig.WorkingDir} && gcc *.c -o main && ./main`,
|
c: `cd ${dockerConfig.WorkingDir} &&
|
||||||
java: `cd ${dockerConfig.WorkingDir} && javac *.java && java Main`,
|
start_time=$(date +%s%N) &&
|
||||||
python: `cd ${dockerConfig.WorkingDir} && python3 script.py`
|
gcc *.c -o main &&
|
||||||
|
compile_time=$(($(date +%s%N) - $start_time)) &&
|
||||||
|
echo "编译时间: $((compile_time / 1000000))ms" &&
|
||||||
|
start_time=$(date +%s%N) &&
|
||||||
|
./main &&
|
||||||
|
run_time=$(($(date +%s%N) - $start_time)) &&
|
||||||
|
echo "运行时间: $((run_time / 1000000))ms"`,
|
||||||
|
java: `cd ${dockerConfig.WorkingDir} &&
|
||||||
|
start_time=$(date +%s%N) &&
|
||||||
|
javac *.java &&
|
||||||
|
compile_time=$(($(date +%s%N) - $start_time)) &&
|
||||||
|
echo "编译时间: $((compile_time / 1000000))ms" &&
|
||||||
|
start_time=$(date +%s%N) &&
|
||||||
|
java Main &&
|
||||||
|
run_time=$(($(date +%s%N) - $start_time)) &&
|
||||||
|
echo "运行时间: $((run_time / 1000000))ms"`,
|
||||||
|
python: `cd ${dockerConfig.WorkingDir} &&
|
||||||
|
start_time=$(date +%s%N) &&
|
||||||
|
python3 script.py &&
|
||||||
|
run_time=$(($(date +%s%N) - $start_time)) &&
|
||||||
|
echo "运行时间: $((run_time / 1000000))ms"`
|
||||||
}[language];
|
}[language];
|
||||||
console.log(`[PERF] 命令准备耗时: ${(performance.now() - stageStart).toFixed(2)}ms`);
|
console.log(`[PERF] 命令准备耗时: ${(performance.now() - stageStart).toFixed(2)}ms`);
|
||||||
|
|
||||||
@ -118,7 +138,7 @@ export const runMultiFileCodeWithOptionalTestData = async (params: {
|
|||||||
const logStream = new Writable({
|
const logStream = new Writable({
|
||||||
write(chunk, _, callback) {
|
write(chunk, _, callback) {
|
||||||
output += chunk.toString()
|
output += chunk.toString()
|
||||||
.replace(/[\x00-\x1F\x7F]/g, '')
|
.replace(/[\x00-\x1F\x7F]/g, '') // Remove non-printable characters
|
||||||
.trim();
|
.trim();
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user