You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于OpenSSL平均耗时测试逻辑,如何获取其最大内存消耗?

How to Track OpenSSL's Maximum Memory Usage Over 5 Runs

Got it, let's adjust your existing script to measure maximum memory consumption instead of average execution time. Here's a straightforward implementation that follows the same loop-based testing approach:

Modified Script

#!/bin/sh 
MAX_MEM=0 
for i in {1..5} 
do 
    # Capture maximum resident memory size (in KB) using /usr/bin/time
    current_mem=$((/usr/bin/time -f '%M' openssl enc -aes-128-ecb -K 1234567890 -in t -out g 1> /dev/null) 2>&1) 
    # Update MAX_MEM if current run used more memory
    if [ "$current_mem" -gt "$MAX_MEM" ]; then
        MAX_MEM="$current_mem"
    fi
done 
echo "Maximum memory usage across 5 runs: $MAX_MEM KB"

Key Changes Explained

  • Memory Metric: We swapped the time format flag from %e (elapsed time) to %M, which returns the maximum resident set size — the peak amount of physical memory the process used during its runtime, measured in KB.
  • Tracking Logic: Instead of summing values for an average, we initialize MAX_MEM to 0 and update it only when the current run's memory usage exceeds the stored maximum.
  • Integer Comparison: Since %M outputs an integer, we use shell's built-in integer comparison (-gt) instead of bc for simplicity.

Notes

  • Make sure you're using /usr/bin/time (the standalone utility) rather than your shell's built-in time command — the built-in version may not support the -f format flag.
  • The input file t and output file g should exist (or adjust the paths) to avoid errors during the OpenSSL execution.

内容的提问来源于stack exchange,提问作者Moser José

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:41:34